string-concat.c
5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// RUN: %clang_cc1 -x c -Wstring-concatenation -fsyntax-only -verify %s
// RUN: %clang_cc1 -x c++ -Wstring-concatenation -fsyntax-only -verify %s
const char *missing_comma[] = {
"basic_filebuf",
"basic_ios",
"future",
"optional",
"packaged_task" // expected-note{{place parentheses around the string literal to silence warning}}
"promise", // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
"shared_future"
};
#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t;
#endif
const wchar_t *missing_comma_wchar[] = {
L"basic_filebuf",
L"packaged_task" // expected-note{{place parentheses around the string literal to silence warning}}
L"promise", // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
L"shared_future"
};
#if __cplusplus >= 201103L
const char *missing_comma_u8[] = {
u8"basic_filebuf",
u8"packaged_task" // expected-note{{place parentheses around the string literal to silence warning}}
u8"promise", // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
u8"shared_future"
};
#endif
const char *missing_comma_same_line[] = {"basic_filebuf", "basic_ios",
"future" "optional", // expected-note{{place parentheses around the string literal to silence warning}}
"packaged_task", "promise"}; // expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
const char *missing_comma_different_lines[] = {"basic_filebuf", "basic_ios" // expected-note{{place parentheses around the string literal to silence warning}}
"future", "optional", // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
"packaged_task", "promise"};
const char *missing_comma_same_line_all_literals[] = {"basic_filebuf", "future" "optional", "packaged_task"}; // expected-note{{place parentheses around the string literal to silence warning}}
// expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
char missing_comma_inner[][5] = {
"a",
"b",
"c" // expected-note{{place parentheses around the string literal to silence warning}}
"d" // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
};
const char *warn[] = { "cpll", "gpll", "hdmiphy" "usb480m" }; // expected-note{{place parentheses around the string literal to silence warning}}
// expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
const char *missing_two_commas_ignore[] = {"basic_filebuf",
"basic_ios"
"future"
"optional",
"packaged_task"};
#define ONE(x) x
#define TWO "foo"
const char *macro_test[] = { ONE("foo"),
TWO,
"foo" TWO // expected-note{{place parentheses around the string literal to silence warning}}
}; // expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
// Do not warn for macros.
#define BASIC_IOS "basic_ios"
#define FUTURE "future"
const char *macro_test2[] = {"basic_filebuf", BASIC_IOS
FUTURE, "optional",
"packaged_task", "promise"};
#define FOO(xx) xx "_normal", \
xx "_movable",
const char *macro_test3[] = {"basic_filebuf",
"basic_ios",
FOO("future")
"optional",
"packaged_task"};
#define BAR(name) #name "_normal"
const char *macro_test4[] = {"basic_filebuf",
"basic_ios",
BAR(future),
"optional",
"packaged_task"};
#define SUPPRESS(x) x
const char *macro_test5[] = { SUPPRESS("foo" "bar"), "baz" };
typedef struct {
int i;
const char s[11];
} S;
S s = {1, "hello" "world"};
const char *not_warn[] = {
"hello"
"world", "test"
};
const char *not_warn2[] = {
"// Aaa\\\n" " Bbb\\ \n" " Ccc?" "?/\n",
"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
"// Aaa\\\r" " Bbb\\ \r" " Ccc?" "?/\r"
};
const char *not_warn3[] = {
"// \\tparam aaa Bbb\n",
"// \\tparam\n"
"// aaa Bbb\n",
"// \\tparam \n"
"// aaa Bbb\n",
"// \\tparam aaa\n"
"// Bbb\n"
};
const char *not_warn4[] = {"title",
"aaaa "
"bbbb "
"cccc "
"ddd.",
"url"
};
typedef struct {
const char *a;
const char *b;
const char *c;
} A;
const A not_warn5 = (A){"",
""
"",
""};
#ifdef __cplusplus
const A not_warn6 = A{"",
""
"",
""};
#endif
static A not_warn7 = {"",
""
"",
""};
// Do not warn when all the elements in the initializer are concatenated together.
const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
// Warning can be supressed also by extra parentheses.
const char *extra_parens_to_suppress_warning[] = {
"basic_filebuf",
"basic_ios",
"future",
"optional",
("packaged_task"
"promise"),
"shared_future"
};