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