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 more wrong...



details:   https://anonhg.NetBSD.org/src/rev/958fff22e313
branches:  trunk
changeset: 1022642:958fff22e313
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 31 10:09:03 2021 +0000

description:
tests/lint: demonstrate more wrong warnings for const struct members

The code 't_const = false' occurs 4 times in the lint code, each
corresponding to one of the wrong warnings in the test.

This bug has been existing at least since 2001.  Back then, the lint
output was:

2001.12.24.20.52.09
| (23): lint error: popctrl() 1
| (15): syntax error [249]
| (19): warning: left operand of 'FARG' must be modifiable lvalue [115]
| (21): syntax error [249]
| (23): warning: function initialize_const_struct_member falls off bottom without returning value [217]
| exit status 1

from 2002.12.06.03.27.39
| (23): lint error: func.c, 168: popctrl()
| (15): warning: left operand of '=' must be modifiable lvalue [115]
| (19): warning: left operand of 'FARG' must be modifiable lvalue [115]
| (21): syntax error [249]
| (23): warning: function initialize_const_struct_member falls off bottom without returning value [217]
| exit status 1
until 2003.10.27.00.12.44

diffstat:

 tests/usr.bin/xlint/lint1/msg_115.c   |  39 ++++++++++++++++++++++++----------
 tests/usr.bin/xlint/lint1/msg_115.exp |   5 +++-
 2 files changed, 31 insertions(+), 13 deletions(-)

diffs (68 lines):

diff -r c6f9f534ac2b -r 958fff22e313 tests/usr.bin/xlint/lint1/msg_115.c
--- a/tests/usr.bin/xlint/lint1/msg_115.c       Sat Jul 31 10:07:22 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_115.c       Sat Jul 31 10:09:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_115.c,v 1.5 2021/07/31 09:14:47 rillig Exp $       */
+/*     $NetBSD: msg_115.c,v 1.6 2021/07/31 10:09:03 rillig Exp $       */
 # 3 "msg_115.c"
 
 // Test for message: %soperand of '%s' must be modifiable lvalue [115]
@@ -16,20 +16,35 @@
        (*const_ptr)++;         /* expect: 115 */
 }
 
-void
+typedef struct {
+       int const member;
+} const_member;
+
+void take_const_member(const_member);
+
+/* see typeok_assign, has_constant_member */
+const_member
 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;
+       const_member cm1 = (const_member) { 12345 };
+       if (cm1.member != 0)
+               /* FIXME: In a function call, const members can be assigned. */
+               /* expect+1: warning: left operand of 'farg' must be modifiable lvalue [115] */
+               take_const_member(cm1);
 
-       struct S s2 = { 12345 };
-       if (s2.member != 0)
-               return;
+       struct {
+               const_member member;
+       } cm2 = {
+           /* FIXME: In an initialization, const members can be assigned. */
+           /* expect+1: warning: left operand of 'init' must be modifiable lvalue [115] */
+           cm1,
+       };
+       if (cm2.member.member != 0) {
+       }
+
+       /* FIXME: In a return statement, const members can be assigned. */
+       /* expect+1: warning: left operand of 'return' must be modifiable lvalue [115] */
+       return cm1;
 }
diff -r c6f9f534ac2b -r 958fff22e313 tests/usr.bin/xlint/lint1/msg_115.exp
--- a/tests/usr.bin/xlint/lint1/msg_115.exp     Sat Jul 31 10:07:22 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_115.exp     Sat Jul 31 10:09:03 2021 +0000
@@ -5,4 +5,7 @@
 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]
+msg_115.c(31): warning: left operand of '=' must be modifiable lvalue [115]
+msg_115.c(35): warning: left operand of 'farg' must be modifiable lvalue [115]
+msg_115.c(42): warning: left operand of 'init' must be modifiable lvalue [115]
+msg_115.c(49): warning: left operand of 'return' must be modifiable lvalue [115]



Home | Main Index | Thread Index | Old Index