1# $NetBSD: cond-op-parentheses.mk,v 1.7 2023/06/01 20:56:35 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# expect+1: Malformed conditional (()
44.if (
45.  error
46.else
47.  error
48.endif
49
50# An unbalanced closing parenthesis is a parse error.
51#
52# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN
53# even though the documentation of that function promised to only ever return
54# TOK_TRUE, TOK_FALSE or TOK_ERROR.  In cond.c 1.241, the return type of that
55# function was changed to a properly restricted enum type, to prevent this bug
56# from occurring again.
57# expect+1: Malformed conditional ())
58.if )
59.  error
60.else
61.  error
62.endif
63
64all:
65	@:;
66