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: demonstrate wrong erro...



details:   https://anonhg.NetBSD.org/src/rev/0686436e1f1c
branches:  trunk
changeset: 984912:0686436e1f1c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 31 09:14:47 2021 +0000

description:
tests/lint: demonstrate wrong error message for initialization

Seen in usr.bin/make/var.c:4022 in C99 mode, where a ModChain variable
is initialized and two of the members are const-qualified.

diffstat:

 tests/usr.bin/xlint/lint1/msg_115.c   |  20 +++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_115.exp |   1 +
 2 files changed, 20 insertions(+), 1 deletions(-)

diffs (39 lines):

diff -r cb1d10357616 -r 0686436e1f1c tests/usr.bin/xlint/lint1/msg_115.c
--- a/tests/usr.bin/xlint/lint1/msg_115.c       Sat Jul 31 00:17:04 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_115.c       Sat Jul 31 09:14:47 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_115.c,v 1.4 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_115.c,v 1.5 2021/07/31 09:14:47 rillig Exp $       */
 # 3 "msg_115.c"
 
 // Test for message: %soperand of '%s' must be modifiable lvalue [115]
@@ -15,3 +15,21 @@
        *const_ptr %= 9;        /* expect: 115 */
        (*const_ptr)++;         /* expect: 115 */
 }
+
+void
+initialize_const_struct_member(void)
+{
+       struct S {
+               int const member;
+       };
+
+       /* FIXME: In an initialization, const members can be assigned. */
+       /* expect+1: warning: left operand of '=' must be modifiable lvalue [115] */
+       struct S s1 = (struct S) { 12345 };
+       if (s1.member != 0)
+               return;
+
+       struct S s2 = { 12345 };
+       if (s2.member != 0)
+               return;
+}
diff -r cb1d10357616 -r 0686436e1f1c tests/usr.bin/xlint/lint1/msg_115.exp
--- a/tests/usr.bin/xlint/lint1/msg_115.exp     Sat Jul 31 00:17:04 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_115.exp     Sat Jul 31 09:14:47 2021 +0000
@@ -5,3 +5,4 @@
 msg_115.c(14): warning: left operand of '/=' must be modifiable lvalue [115]
 msg_115.c(15): warning: left operand of '%=' must be modifiable lvalue [115]
 msg_115.c(16): warning: operand of 'x++' must be modifiable lvalue [115]
+msg_115.c(28): warning: left operand of '=' must be modifiable lvalue [115]



Home | Main Index | Thread Index | Old Index