* c-common.c (braced_list_to_string): Remove eval parameter.
[official-gcc.git] / gcc / testsuite / g++.dg / init / string2.C
blob19ae6b4ef1ced986d4c61e23d52efd96687e74a1
1 // PR tree-optimization/71625 - missing strlen optimization on different
2 // array initialization style
3 //
4 // Verify that strlen() calls with constant character array arguments
5 // initialized with string constants are folded.  (This is a small
6 // subset of pr71625).
7 // { dg-do compile }
8 // { dg-options "-O0 -Wno-error=narrowing -fdump-tree-gimple" }
10 #define A(expr) do { typedef char A[-1 + 2 * !!(expr)]; } while (0)
12 /* This is undefined but accepted without -Wpedantic.  Verify that
13    the size is zero.  */
14 const char ax[] = { };
16 void size0 ()
18   A (sizeof ax == 0);
21 const char a0[] = { 'a', 'b', 'c', '\0' };
23 int len0 ()
25   return __builtin_strlen (a0);
28 // Verify that narrowing warnings are preserved.
29 const signed char
30 sa0[] = { 'a', 'b', 255, '\0' };    // { dg-warning "\\\[\(-Wnarrowing|-Woverflow\)" "" { target { ! c++98_only } } }
32 int lens0 ()
34   return __builtin_strlen ((const char*)sa0);
37 const unsigned char
38 ua0[] = { 'a', 'b', -1, '\0' };     // { dg-warning "\\\[\(-Wnarrowing|-Woverflow\)" "" { target { ! c++98_only } } }
40 int lenu0 ()
42   return __builtin_strlen ((const char*)ua0);
45 const char c = 0;
46 const char a1[] = { 'a', 'b', 'c', c };
48 int len1 ()
50   return __builtin_strlen (a1);
53 template <class T>
54 int tmplen ()
56   static const T
57     a[] = { 1, 2, 333, 0 };         // { dg-warning "\\\[\(-Wnarrowing|-Woverflow\)" }
58   return __builtin_strlen (a);
61 template int tmplen<char>();
63 const wchar_t ws4[] = { 1, 2, 3, 4 };
64 const wchar_t ws7[] = { 1, 2, 3, 4, 0, 0, 0 };
65 const wchar_t ws9[9] = { 1, 2, 3, 4, 0 };
67 void wsize ()
69   A (sizeof ws4 == 4 * sizeof *ws4);
70   A (ws4[0] == 1 && ws4[1] == 2 && ws4[2] == 3 && ws4[3] == 4);
72   A (sizeof ws7 == 7 * sizeof *ws7);
73   A (ws7[0] == 1 && ws7[1] == 2 && ws7[2] == 3 && ws7[4] == 4
74      && !ws7[5] && !ws7[6]);
76   A (sizeof ws9 == 9 * sizeof *ws9);
77   A (ws9[0] == 1 && ws9[1] == 2 && ws9[2] == 3 && ws9[4] == 4
78      && !ws9[5] && !ws9[6] && !ws9[7] && !ws9[8]);
81 #if 0
83 // The following aren't handled.
85 const char &cref = c;
86 const char a2[] = { 'a', 'b', 'c', cref };
88 int len2 ()
90   return __builtin_strlen (a2);
94 const char* const cptr = &cref;
95 const char a3[] = { 'a', 'b', 'c', *cptr };
97 int len3 ()
99   return __builtin_strlen (a3);
102 #endif
104 // { dg-final { scan-tree-dump-times "strlen" 0 "gimple" } }