PR c++/56973, DR 696 - capture constant variables only as needed.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / pr58708.C
blobb46e54bbca3e3dddc6a9f315d64719bc0b44e132
1 // { dg-do run { target c++14 } }
3 template<typename, typename>
4   struct is_same
5   {
6     static constexpr bool value = false;
7   };
9 template<typename _Tp>
10   struct is_same<_Tp, _Tp>
11   {
12     static constexpr bool value = true;
13   };
15 template<typename CharT, CharT... Str>
16   struct Foo
17   {
18     using char_type = CharT;
19     char_type chars[sizeof...(Str)]{Str...};
20   };
22 template<typename CharT, CharT... Str>
23   Foo<CharT, Str...>
24   operator""_foo()
25   {
26     return Foo<CharT, Str...>();
27   }
29 int
30 main()
32   auto fooU = U"\x10000\x10001\x10002"_foo;
33   if (is_same<decltype(fooU)::char_type, char32_t>::value != true) __builtin_abort();
34   if (sizeof(fooU.chars)/sizeof(char32_t) != 3) __builtin_abort();
35   if (fooU.chars[0] != 65536) __builtin_abort();
36   if (fooU.chars[1] != 65537) __builtin_abort();
37   if (fooU.chars[2] != 65538) __builtin_abort();
39   auto foo = "\x61\x62\x63"_foo;
40   if (is_same<decltype(foo)::char_type, char>::value != true) __builtin_abort();
41   if (sizeof(foo.chars)/sizeof(char) != 3) __builtin_abort();
42   if (foo.chars[0] != 97) __builtin_abort();
43   if (foo.chars[1] != 98) __builtin_abort();
44   if (foo.chars[2] != 99) __builtin_abort();
46 #if __SIZEOF_WCHAR_T__ == 2
47     auto wfoo = L"\x0102\x0304"_foo;
48 #else
49     auto wfoo = L"\x01020304\x05060708"_foo;
50 #endif
51   if (is_same<decltype(wfoo)::char_type, wchar_t>::value != true) __builtin_abort();
52   if (sizeof(wfoo.chars)/sizeof(wchar_t) != 2) __builtin_abort();
53 #if __SIZEOF_WCHAR_T__ == 2
54   if (wfoo.chars[0] != 258) __builtin_abort();
55   if (wfoo.chars[1] != 772) __builtin_abort();
56 #else
57   if (wfoo.chars[0] != 16909060) __builtin_abort();
58   if (wfoo.chars[1] != 84281096) __builtin_abort();
59 #endif
61   auto foou = u"\x0102\x0304\x0506\x0708"_foo;
62   if (is_same<decltype(foou)::char_type, char16_t>::value != true) __builtin_abort();
63   if (sizeof(foou.chars)/sizeof(char16_t) != 4) __builtin_abort();
64   if (foou.chars[0] != 258) __builtin_abort();
65   if (foou.chars[1] != 772) __builtin_abort();
66   if (foou.chars[2] != 1286) __builtin_abort();
67   if (foou.chars[3] != 1800) __builtin_abort();