1# $NetBSD: cond-op-parentheses.mk,v 1.6 2022/09/04 22:55:00 rillig Exp $
2#
3# Tests for parentheses in .if conditions, which group expressions to override
4# the precedence of the operators '!', '&&' and '||'.  Parentheses cannot be
5# used to form arithmetic expressions such as '(3+4)' though.
6
7# Contrary to the C family of programming languages, the outermost condition
8# does not have to be enclosed in parentheses.
9.if defined(VAR)
10.  error
11.elif !1
12.  error
13.endif
14
15# Parentheses cannot enclose numbers as there is no need for it.  Make does
16# not implement any arithmetic functions in its condition parser.  If
17# absolutely necessary, use expr(1).
18#
19# XXX: It's inconsistent that the right operand has unbalanced parentheses.
20#
21# expect+1: Comparison with '>' requires both operands '3' and '(2' to be numeric
22.if 3 > (2)
23.endif
24# expect+1: Malformed conditional ((3) > 2)
25.if (3) > 2
26.endif
27
28# Test for deeply nested conditions.
29.if	((((((((((((((((((((((((((((((((((((((((((((((((((((((((	\
30	((((((((((((((((((((((((((((((((((((((((((((((((((((((((	\
31	1								\
32	))))))))))))))))))))))))))))))))))))))))))))))))))))))))	\
33	))))))))))))))))))))))))))))))))))))))))))))))))))))))))
34# Parentheses can be nested at least to depth 112.  There is nothing special
35# about this number though, much higher numbers work as well, at least on
36# NetBSD.  The actual limit depends on the allowed call stack depth for C code
37# of the platform.  Anyway, 112 should be enough for all practical purposes.
38.else
39.  error
40.endif
41
42# An unbalanced opening parenthesis is a parse error.
43.if (
44.  error
45.else
46.  error
47.endif
48
49# An unbalanced closing parenthesis is a parse error.
50#
51# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN
52# even though the documentation of that function promised to only ever return
53# TOK_TRUE, TOK_FALSE or TOK_ERROR.  In cond.c 1.241, the return type of that
54# function was changed to a properly restricted enum type, to prevent this bug
55# from occurring again.
56.if )
57.  error
58.else
59.  error
60.endif
61
62all:
63	@:;
64