Module Name:    src
Committed By:   rillig
Date:           Sat Jul 31 10:09:03 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_115.c msg_115.exp

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_115.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_115.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_115.c
diff -u src/tests/usr.bin/xlint/lint1/msg_115.c:1.5 src/tests/usr.bin/xlint/lint1/msg_115.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_115.c:1.5	Sat Jul 31 09:14:47 2021
+++ src/tests/usr.bin/xlint/lint1/msg_115.c	Sat Jul 31 10:09:03 2021
@@ -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 @@ example(const int *const_ptr)
 	(*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;
-
-	struct S s2 = { 12345 };
-	if (s2.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 {
+		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;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_115.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_115.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_115.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_115.exp:1.4	Sat Jul 31 09:14:47 2021
+++ src/tests/usr.bin/xlint/lint1/msg_115.exp	Sat Jul 31 10:09:03 2021
@@ -5,4 +5,7 @@ msg_115.c(13): warning: left operand of 
 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]

Reply via email to