Module Name:    src
Committed By:   rillig
Date:           Mon Aug 16 16:19:47 UTC 2021

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

Log Message:
tests/lint: document history of initialization of const members


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_115.c
cvs rdiff -u -r1.7 -r1.8 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.8 src/tests/usr.bin/xlint/lint1/msg_115.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_115.c:1.8	Sat Aug 14 12:46:24 2021
+++ src/tests/usr.bin/xlint/lint1/msg_115.c	Mon Aug 16 16:19:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_115.c,v 1.8 2021/08/14 12:46:24 rillig Exp $	*/
+/*	$NetBSD: msg_115.c,v 1.9 2021/08/16 16:19:47 rillig Exp $	*/
 # 3 "msg_115.c"
 
 // Test for message: %soperand of '%s' must be modifiable lvalue [115]
@@ -14,6 +14,10 @@ example(const int *const_ptr)
 	*const_ptr /= 5;	/* expect: 115 */
 	*const_ptr %= 9;	/* expect: 115 */
 	(*const_ptr)++;		/* expect: 115 */
+
+	/* In the next example, the left operand is not an lvalue at all. */
+	/* expect+1: error: left operand of '=' must be lvalue [114] */
+	(const_ptr + 3) = const_ptr;
 }
 
 typedef struct {
@@ -22,7 +26,15 @@ typedef struct {
 
 void take_const_member(const_member);
 
-/* see typeok_assign, has_constant_member */
+/*
+ * Before init.c 1.208 from 2021-08-14 and decl.c 1.221 from 2021-08-10,
+ * lint issued a wrong "warning: left operand of '%s' must be modifiable
+ * lvalue", even in cases where the left operand was being initialized
+ * instead of overwritten.
+ *
+ * See initialization_expr_using_op, typeok_assign, has_constant_member.
+ * See C99 6.2.5p25.
+ */
 const_member
 initialize_const_struct_member(void)
 {

Index: src/tests/usr.bin/xlint/lint1/msg_115.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_115.exp:1.7 src/tests/usr.bin/xlint/lint1/msg_115.exp:1.8
--- src/tests/usr.bin/xlint/lint1/msg_115.exp:1.7	Sat Aug 14 12:46:24 2021
+++ src/tests/usr.bin/xlint/lint1/msg_115.exp	Mon Aug 16 16:19:47 2021
@@ -5,3 +5,4 @@ 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(20): error: left operand of '=' must be lvalue [114]

Reply via email to