Thu Jul 15 17:48:10 2021 UTC ()
tests/lint: explain global variables in __attribute__


(rillig)
diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/expr_precedence.c
diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/expr_precedence.exp

cvs diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/expr_precedence.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/expr_precedence.c 2021/07/15 17:20:58 1.2
+++ src/tests/usr.bin/xlint/lint1/expr_precedence.c 2021/07/15 17:48:10 1.3
@@ -1,30 +1,38 @@ @@ -1,30 +1,38 @@
1/* $NetBSD: expr_precedence.c,v 1.2 2021/07/15 17:20:58 rillig Exp $ */ 1/* $NetBSD: expr_precedence.c,v 1.3 2021/07/15 17:48:10 rillig Exp $ */
2# 3 "expr_precedence.c" 2# 3 "expr_precedence.c"
3 3
4/* 4/*
5 * Tests for the precedence among operators. 5 * Tests for the precedence among operators.
6 */ 6 */
7 7
8int var; 8int var;
9 9
10/* 10/*
11 * An initializer needs an assignment-expression; the comma must be 11 * An initializer needs an assignment-expression; the comma must be
12 * interpreted as a separator, not an operator. 12 * interpreted as a separator, not an operator.
13 */ 13 */
14/* expect+1: error: syntax error '4' [249] */ 14/* expect+1: error: syntax error '4' [249] */
15int init_error = 3, 4; 15int init_error = 3, 4;
16 16
17/* expect+1: error: non-constant initializer [177] */ 17/* expect+1: error: non-constant initializer [177] */
18int init_syntactically_ok = var = 1 ? 2 : 3; 18int init_syntactically_ok = var = 1 ? 2 : 3;
19 19
20/* 20/*
21 * The arguments of __attribute__ must be constant-expression, as assignments 21 * The arguments of __attribute__ must be constant-expression, as assignments
22 * don't make sense at that point. 22 * don't make sense at that point.
23 */ 23 */
24void __attribute__((format(printf, 24void __attribute__((format(printf,
25 /* expect+2: error: 'var' undefined [99] */ /* XXX: why? */ 25 /*
 26 * Inside of __attribute__((...)), symbol lookup works differently. For
 27 * example, 'printf' is a keyword, and since all arguments to
 28 * __attribute__ are constant expressions, looking up global variables
 29 * would not make sense. Therefore, 'var' is undefined.
 30 *
 31 * See lex.c, function 'search', keyword 'attron'.
 32 */
 33 /* expect+2: error: 'var' undefined [99] */
26 /* expect+1: syntax error '=' [249] */ 34 /* expect+1: syntax error '=' [249] */
27 var = 1, 35 var = 1,
28 /* Syntactically ok, must be a constant expression though. */ 36 /* Syntactically ok, must be a constant expression though. */
29 var > 0 ? 2 : 1))) 37 var > 0 ? 2 : 1)))
30my_printf(const char *, ...); 38my_printf(const char *, ...);

cvs diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/Attic/expr_precedence.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/expr_precedence.exp 2021/07/15 17:20:58 1.2
+++ src/tests/usr.bin/xlint/lint1/Attic/expr_precedence.exp 2021/07/15 17:48:10 1.3
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
1expr_precedence.c(15): error: syntax error '4' [249] 1expr_precedence.c(15): error: syntax error '4' [249]
2expr_precedence.c(18): error: non-constant initializer [177] 2expr_precedence.c(18): error: non-constant initializer [177]
3expr_precedence.c(27): error: 'var' undefined [99] 3expr_precedence.c(35): error: 'var' undefined [99]
4expr_precedence.c(27): error: syntax error '=' [249] 4expr_precedence.c(35): error: syntax error '=' [249]