Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: document an example of...



details:   https://anonhg.NetBSD.org/src/rev/3f3d3af63c9e
branches:  trunk
changeset: 378125:3f3d3af63c9e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 21 05:51:12 2023 +0000

description:
tests/lint: document an example of a non-constant initializer

diffstat:

 tests/usr.bin/xlint/lint1/msg_181.c |  15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r 4073acabb4ea -r 3f3d3af63c9e tests/usr.bin/xlint/lint1/msg_181.c
--- a/tests/usr.bin/xlint/lint1/msg_181.c       Fri Jul 21 02:42:54 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_181.c       Fri Jul 21 05:51:12 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_181.c,v 1.5 2023/03/28 14:44:35 rillig Exp $       */
+/*     $NetBSD: msg_181.c,v 1.6 2023/07/21 05:51:12 rillig Exp $       */
 # 3 "msg_181.c"
 
 // Test for message: {}-enclosed initializer required [181]
@@ -8,3 +8,16 @@
 /* expect+1: error: {}-enclosed initializer required [181] */
 struct { int x; } missing_braces = 3;
 struct { int x; } including_braces = { 3 };
+
+
+// C11 6.6p7 requires the initializer of an object with static storage duration
+// to be a constant expression or an address constant, and a compound literal
+// is neither.  C11 6.6p10 allows an implementation to accept "other forms of
+// constant expressions", and GCC accepts compound literals that contain only
+// constant expressions.
+struct number {
+       int value;
+} num = (struct number){
+    .value = 3,
+};
+/* expect-1: error: {}-enclosed initializer required [181] */



Home | Main Index | Thread Index | Old Index