Module Name: src
Committed By: rillig
Date: Mon Mar 22 16:51:24 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_171.c
Log Message:
tests/lint: explain wrong type mismatch in compound literal
When a pointer to a compound literal is used as an initializer, lint
reports a wrong type mismatch. The details of what happens are now
documented, which allows this problem to be fixed properly.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_171.c
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.4 src/tests/usr.bin/xlint/lint1/msg_171.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_171.c:1.4 Mon Mar 22 15:29:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_171.c Mon Mar 22 16:51:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_171.c,v 1.4 2021/03/22 15:29:43 rillig Exp $ */
+/* $NetBSD: msg_171.c,v 1.5 2021/03/22 16:51:24 rillig Exp $ */
# 3 "msg_171.c"
// Test for message: cannot assign to '%s' from '%s' [171]
@@ -34,4 +34,20 @@ pointer_to_compound_literal(void)
struct point *p = &(struct point){
12, 5,
}; /* expect: 171 *//*FIXME*/
+ /*
+ * FIXME: The type mismatch in the above line occurs because lint
+ * wrongly assumes that there is only ever a single initialization
+ * going on, which takes place in initstk.
+ *
+ * In the debug log, this is marked by the two calls to initstack_init
+ * that are happily intermixed with 'begin initialization' and 'end
+ * initialization'. This was not planned for, and it worked well
+ * before C99, since compound literals are a new feature from C99.
+ *
+ * The proper fix, as for so many similar problems is to not use
+ * global variables for things that have a limited lifetime, but
+ * instead let the grammar determine the lifetime and scope of these
+ * objects, which makes them only accessible when they can actually be
+ * used.
+ */
}