Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/nontype-class40.C

raw
1 // PR c++/93083
2 // { dg-do compile { target c++20 } }
3
4 template<unsigned N>
5 struct FixedString
6 {
7 char buf[N + 1]{};
8 constexpr FixedString(char const* s) {
9 for (unsigned i = 0; i != N; ++i) buf[i] = s[i];
10 }
11
12 auto operator<=>(const FixedString&) const = default;
13 constexpr operator char const*() const { return buf; }
14 constexpr static unsigned size() noexcept { return N; }
15 };
16
17 template<unsigned N> FixedString(char const (&)[N]) -> FixedString<N - 1>;
18
19 template <FixedString... names>
20 struct name_list
21 {
22 template <FixedString name>
23 using add_name = name_list<
24 names...,
25 FixedString<name.size()>{ name }
26 >;
27 };
28
29
30 int main()
31 {
32 using names =
33 name_list<>
34 ::add_name<"Zaphod Beeblebrox">;
35
36 }
37
38 // ----------------
39
40 template <int N> struct literal {
41 constexpr literal(const char (&input)[N]) noexcept { }
42 constexpr literal(const literal &) noexcept { }
43 };
44
45 template <literal Name, int id> struct field { };
46
47 template <literal Name> struct field<Name, 1u> { };
48
49 // ----------------
50
51 template <int N>
52 struct use_as_nttp {};
53
54 template <use_as_nttp Value>
55 struct has_nttp {};
56
57 template <use_as_nttp Value>
58 using has_nttp_2 = has_nttp<Value>;
59
60 // ----------------
61
62 using size_t = decltype(sizeof(0));
63
64 template <size_t N>
65 struct string_literal
66 {
67 constexpr string_literal(const char*) {}
68 string_literal(string_literal const&) = default;
69 };
70 template <size_t N>
71 string_literal(const char (&)[N]) -> string_literal<N - 1>;
72
73 template <string_literal Str>
74 struct type_string { };
75
76 template <string_literal Str>
77 void foo() {
78 type_string<Str>{};
79 }