brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.9 KiB · 63abf10 Raw
171 lines · c
1 2// RUN: %clang_cc1 -x c -Wstring-concatenation -fsyntax-only -verify %s3// RUN: %clang_cc1 -x c++ -Wstring-concatenation -fsyntax-only -verify %s4 5const 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 __cplusplus16typedef __WCHAR_TYPE__ wchar_t;17#endif18 19const 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 >= 201103L27const 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#endif34 35const 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 39const 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 43const 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 46char 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 53const 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 56const char *missing_two_commas_ignore[] = {"basic_filebuf",57                       "basic_ios" 58                       "future"  59                       "optional",60                       "packaged_task"};61 62#define ONE(x) x63#define TWO "foo"64const 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"73const char *macro_test2[] = {"basic_filebuf", BASIC_IOS74                        FUTURE, "optional",75                       "packaged_task", "promise"};76 77#define FOO(xx) xx "_normal", \78                xx "_movable",79 80const char *macro_test3[] = {"basic_filebuf",81                       "basic_ios",82                       FOO("future")83                       "optional",84                       "packaged_task"};85 86#define BAR(name) #name "_normal"87 88const char *macro_test4[] = {"basic_filebuf",89                       "basic_ios",90                       BAR(future),91                       "optional",92                       "packaged_task"};93 94#define SUPPRESS(x) x95const char *macro_test5[] = { SUPPRESS("foo" "bar"), "baz" };96 97typedef struct {98    int i;99    const char s[11];100} S;101 102S s = {1, "hello" "world"};103 104const char *not_warn[] = {105    "hello"106    "world", "test"107};108 109const 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 115const 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 125const char *not_warn4[] =  {"title",126               "aaaa "127               "bbbb "128               "cccc "129               "ddd.",130               "url"131};132 133typedef struct {134  const char *a;135  const char *b;136  const char *c;137} A;138 139const A not_warn5 = (A){"",140                        ""141                        "",142                        ""};143 144#ifdef __cplusplus145const A not_warn6 =  A{"",146                      ""147                      "",148                      ""};149#endif150 151static A not_warn7 = {"",152 153  ""154  "",155  ""};156 157 158// Do not warn when all the elements in the initializer are concatenated together.159const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};160 161// Warning can be supressed also by extra parentheses.162const 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