lsym_lparen_or_lbracket.c revision 1.3 1 1.3 rillig /* $NetBSD: lsym_lparen_or_lbracket.c,v 1.3 2022/02/13 12:04:37 rillig Exp $ */
2 1.1 rillig /* $FreeBSD$ */
3 1.1 rillig
4 1.1 rillig /*
5 1.1 rillig * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
6 1.1 rillig * in these contexts:
7 1.1 rillig *
8 1.1 rillig * In a type name, '(' constructs a function type.
9 1.1 rillig *
10 1.1 rillig * In an expression, '(' starts an inner expression to override the usual
11 1.1 rillig * operator precedence.
12 1.1 rillig *
13 1.1 rillig * In an expression, an identifier followed by '(' starts a function call
14 1.1 rillig * expression.
15 1.1 rillig *
16 1.1 rillig * In a 'sizeof' expression, '(' is required if the argument is a type name.
17 1.1 rillig *
18 1.1 rillig * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling
19 1.1 rillig * expression must be enclosed in '(' and ')'.
20 1.1 rillig *
21 1.1 rillig * In an expression, '(' followed by a type name starts a cast expression.
22 1.1 rillig */
23 1.1 rillig
24 1.3 rillig // TODO: Add systematic tests for all cases.
25 1.3 rillig
26 1.1 rillig #indent input
27 1.3 rillig void
28 1.3 rillig function(void)
29 1.3 rillig {
30 1.3 rillig /* Type casts */
31 1.3 rillig a = (int)b;
32 1.3 rillig a = (struct tag)b;
33 1.3 rillig /* TODO: The '(int)' is not a type cast, it is a prototype list. */
34 1.3 rillig a = (int (*)(int))fn;
35 1.3 rillig
36 1.3 rillig /* Not type casts */
37 1.3 rillig a = sizeof(int) * 2;
38 1.3 rillig a = sizeof(5) * 2;
39 1.3 rillig a = offsetof(struct stat, st_mtime);
40 1.3 rillig
41 1.3 rillig /* Grouping subexpressions */
42 1.3 rillig a = ((((b + c)))) * d;
43 1.3 rillig }
44 1.1 rillig #indent end
45 1.1 rillig
46 1.1 rillig #indent run-equals-input
47 1.2 rillig
48 1.2 rillig /* See t_errors.sh, test case 'compound_literal'. */
49