Module Name: src
Committed By: rillig
Date: Mon Mar 22 15:05:00 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_171.c msg_171.exp
Log Message:
lint: demonstrate bug in assignment of compound literal
Seen in external/mpl/bind/dist/lib/dns/rbtdb.c, update_rrsetstats.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_171.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_171.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/msg_171.c
diff -u src/tests/usr.bin/xlint/lint1/msg_171.c:1.2 src/tests/usr.bin/xlint/lint1/msg_171.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_171.c:1.2 Sun Jan 24 16:12:45 2021
+++ src/tests/usr.bin/xlint/lint1/msg_171.c Mon Mar 22 15:05:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_171.c,v 1.2 2021/01/24 16:12:45 rillig Exp $ */
+/* $NetBSD: msg_171.c,v 1.3 2021/03/22 15:05:00 rillig Exp $ */
# 3 "msg_171.c"
// Test for message: assignment type mismatch (%s != %s) [171]
@@ -17,3 +17,21 @@ example(int i, void *vp, struct s *s)
vp = *s; /* expect: 171 */
*s = vp; /* expect: 171 */
}
+
+/*
+ * C99 6.5.2.5 says that a compound literal evaluates to an unnamed object
+ * with automatic storage duration, like any normal named object. It is an
+ * lvalue, which means that it is possible to take the address of the object.
+ * Seen in external/mpl/bind/dist/lib/dns/rbtdb.c, update_rrsetstats.
+ */
+void
+pointer_to_compound_literal(void)
+{
+ struct point {
+ int x;
+ int y;
+ };
+ struct point *p = &(struct point){
+ 12, 5,
+ }; /* expect: 171 *//*FIXME*/
+}
Index: src/tests/usr.bin/xlint/lint1/msg_171.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_171.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_171.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_171.exp:1.3 Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_171.exp Mon Mar 22 15:05:00 2021
@@ -2,3 +2,4 @@ msg_171.c(14): error: assignment type mi
msg_171.c(15): error: assignment type mismatch (struct != int) [171]
msg_171.c(17): error: assignment type mismatch (pointer != struct) [171]
msg_171.c(18): error: assignment type mismatch (struct != pointer) [171]
+msg_171.c(36): error: assignment type mismatch (struct != pointer) [171]