Debian Codegraph @

gcc/testsuite/g++.dg/cpp1y/pr59867.C

raw
1 // PR c++/59867
2 // { dg-do compile { target c++14 } }
3 // { dg-options -w }
4
5 using namespace std;
6
7 // constant
8 template<typename T, T x>
9 struct meta_value
10 {
11 typedef meta_value type;
12 typedef T value_type;
13 static const T value = x;
14 };
15
16 // array
17 template<typename T, T... data>
18 struct meta_array
19 {
20 typedef meta_array type;
21 typedef T item_type;
22 };
23
24 // static array -> runtime array conversion utility
25 template<typename T>
26 struct array_gen;
27
28 template<typename T, T... xs>
29 struct array_gen<meta_array<T, xs...>>
30 {
31 static const T value[sizeof...(xs)];
32 };
33
34 template<typename T, T... xs>
35 const T
36 array_gen<meta_array<T, xs...>>::value[sizeof...(xs)] = {xs...};
37
38 // static string
39 template<typename T, T... xs>
40 constexpr meta_array<T, xs...>
41 operator""_s()
42 {
43 static_assert(sizeof...(xs) == 3, "What's wrong with you?");
44 return meta_array<T, xs...>();
45 }
46
47 int
48 main()
49 {
50 auto a = "123"_s;
51 const char (& xs)[3] = array_gen<decltype("123"_s)>::value;
52 }