Sun Feb 27 18:51:21 2022 UTC ()
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".


(rillig)
diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_292.c
diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_292.exp

cvs diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_292.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/msg_292.c 2021/02/21 09:07:58 1.2
+++ src/tests/usr.bin/xlint/lint1/msg_292.c 2022/02/27 18:51:21 1.3
@@ -1,7 +1,39 @@ @@ -1,7 +1,39 @@
1/* $NetBSD: msg_292.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ 1/* $NetBSD: msg_292.c,v 1.3 2022/02/27 18:51:21 rillig Exp $ */
2# 3 "msg_292.c" 2# 3 "msg_292.c"
3 3
4// Test for message: cannot concatenate wide and regular string literals [292] 4// Test for message: cannot concatenate wide and regular string literals [292]
5 5
6TODO: "Add example code that triggers the above message." /* expect: 249 */ 6const char c_c_c_w_w_w[] =
7TODO: "Add example code that almost triggers the above message." 7 "c2"
 8 "c 4"
 9 "c 8"
 10 /* expect+1: error: cannot concatenate wide and regular string literals [292] */
 11 L"w2"
 12 /* expect+1: error: cannot concatenate wide and regular string literals [292] */
 13 L"w 4"
 14 /* expect+1: error: cannot concatenate wide and regular string literals [292] */
 15 L"w 8";
 16/* The 15 results from 2 + 4 + 8 + '\0'. */
 17/* expect+1: error: negative array dimension (-15) [20] */
 18typedef int reveal_sizeof_c_c_c_w_w_w[-(int)sizeof(c_c_c_w_w_w)];
 19
 20const char c_w_c_w_c_w[] =
 21 "c2"
 22 L"w2"
 23 /* expect+1: error: cannot concatenate wide and regular string literals [292] */
 24 "c 4"
 25 L"w 4"
 26 /* expect+1: error: cannot concatenate wide and regular string literals [292] */
 27 "c 8"
 28 /* expect+1: error: cannot concatenate wide and regular string literals [292] */
 29 L"w 8";
 30/*
 31 * Concatenating L"w2" with "c4" fails, keeping L"w2".
 32 * Concatenating L"w2" with L"w4" succeeds, resulting in L"w2w4".
 33 * Concatenating L"w2w4" with "c8" fails, keeping L"w2w4".
 34 * Concatenating L"w2w4" with L"w8" succeeds, resulting in L"w2w4w8".
 35 * Concatenating "c2" with L"w2w4w8" fails, keeping "c2".
 36 * The size of "c2" is 3.
 37 */
 38/* expect+1: error: negative array dimension (-3) [20] */
 39typedef int reveal_sizeof_c_w_c_w_c_w[-(int)sizeof(c_w_c_w_c_w)];

cvs diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/Attic/msg_292.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/msg_292.exp 2021/03/21 20:45:00 1.2
+++ src/tests/usr.bin/xlint/lint1/Attic/msg_292.exp 2022/02/27 18:51:21 1.3