Module Name:    src
Committed By:   rillig
Date:           Sun Feb 27 18:51:21 UTC 2022

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

Log Message:
tests/lint: demonstrate unexpected ordering of string concatenations

When lint concatenates the strings "1" "2" "3" "4", it first
concatenates "23", then "234" and finally "1234".


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_292.c \
    src/tests/usr.bin/xlint/lint1/msg_292.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_292.c
diff -u src/tests/usr.bin/xlint/lint1/msg_292.c:1.2 src/tests/usr.bin/xlint/lint1/msg_292.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_292.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_292.c	Sun Feb 27 18:51:21 2022
@@ -1,7 +1,39 @@
-/*	$NetBSD: msg_292.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_292.c,v 1.3 2022/02/27 18:51:21 rillig Exp $	*/
 # 3 "msg_292.c"
 
 // Test for message: cannot concatenate wide and regular string literals [292]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+const char c_c_c_w_w_w[] =
+	"c2"
+	"c  4"
+	"c      8"
+	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
+	L"w2"
+	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
+	L"w  4"
+	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
+	L"w      8";
+/* The 15 results from 2 + 4 + 8 + '\0'. */
+/* expect+1: error: negative array dimension (-15) [20] */
+typedef int reveal_sizeof_c_c_c_w_w_w[-(int)sizeof(c_c_c_w_w_w)];
+
+const char c_w_c_w_c_w[] =
+	"c2"
+	L"w2"
+	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
+	"c  4"
+	L"w  4"
+	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
+	"c      8"
+	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
+	L"w      8";
+/*
+ * Concatenating L"w2" with "c4" fails, keeping L"w2".
+ * Concatenating L"w2" with L"w4" succeeds, resulting in L"w2w4".
+ * Concatenating L"w2w4" with "c8" fails, keeping L"w2w4".
+ * Concatenating L"w2w4" with L"w8" succeeds, resulting in L"w2w4w8".
+ * Concatenating "c2" with L"w2w4w8" fails, keeping "c2".
+ * The size of "c2" is 3.
+ */
+/* expect+1: error: negative array dimension (-3) [20] */
+typedef int reveal_sizeof_c_w_c_w_c_w[-(int)sizeof(c_w_c_w_c_w)];
Index: src/tests/usr.bin/xlint/lint1/msg_292.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_292.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_292.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_292.exp:1.2	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_292.exp	Sun Feb 27 18:51:21 2022
@@ -1 +1,8 @@
-msg_292.c(6): error: syntax error ':' [249]
+msg_292.c(11): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(13): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(15): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(18): error: negative array dimension (-15) [20]
+msg_292.c(24): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(27): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(29): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(39): error: negative array dimension (-3) [20]

Reply via email to