Module Name: src Committed By: rillig Date: Sat Apr 17 20:57:18 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: gcc_init_compound_literal.c gcc_init_compound_literal.exp Log Message: tests/lint: fix analysis from previous commit, add another example This is not a GCC feature, it's required by C99 already. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 \ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c \ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c diff -u src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.1 src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.2 --- src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.1 Sat Apr 17 20:36:17 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c Sat Apr 17 20:57:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: gcc_init_compound_literal.c,v 1.1 2021/04/17 20:36:17 rillig Exp $ */ +/* $NetBSD: gcc_init_compound_literal.c,v 1.2 2021/04/17 20:57:18 rillig Exp $ */ # 3 "gcc_init_compound_literal.c" /* @@ -7,14 +7,11 @@ * All the expressions in an initializer for an object that has static * storage duration shall be constant expressions or string literals. * - * The term "constant expression" is defined in C99 6.6 and is quite - * restricted, except for a single paragraph, 6.6p10: - * - * An implementation may accept other forms of constant expressions. - * - * GCC additionally allows compound expressions, and these can even use the - * array-to-pointer conversion from C99 6.3.2.1, which allows to initialize a - * pointer object with a pointer to a direct-value statically allocated array. + * The term "constant expression" is defined in C99 6.6, where 6.6p9 allows + * "constant expressions" in initializers to also be an "address constant". + * Using these address constants, it is possible to reference an unnamed + * object created by a compound literal (C99 6.5.2.5), using either an + * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1. */ // Seen in sys/crypto/aes/aes_ccm.c. @@ -28,3 +25,33 @@ const struct { // 1, 2, 3, 4 // }, }; + +struct node { + int num; + struct node *left; + struct node *right; +}; + +/* + * Initial tree for representing the decisions in the classic number guessing + * game often used in teaching the basics of programming. + */ +/* TODO: activate after fixing the assertion failure +static const struct node guess = { + 50, + &(struct node){ + 25, + &(struct node){ + 12, + (void *)0, + (void *)0, + }, + &(struct node){ + 37, + (void *)0, + (void *)0, + }, + }, + (void *)0 +}; +*/ Index: src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp diff -u src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.1 src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.2 --- src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.1 Sat Apr 17 20:36:17 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp Sat Apr 17 20:57:18 2021 @@ -1 +1 @@ -gcc_init_compound_literal.c(25): error: too many struct/union initializers [172] +gcc_init_compound_literal.c(22): error: too many struct/union initializers [172]