Debian Codegraph @

clang/test/SemaCXX/ctad.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s
2
3 namespace GH39811 {
4
5 template<int = 0> class C {};
6
7 C (a);
8 C (b) = C();
9 C (c) {};
10 C (((((d)))));
11
12 template<C (e)> class X;
13 template<C (...f)> class Y;
14
15 void test() {
16 C (g);
17 C (h) = C();
18 C (i) {};
19 (void)g;
20 (void)h;
21 (void)i;
22 }
23
24 C* (bad1); // expected-error {{cannot form pointer to deduced class template specialization type}}
25 C (*bad2); // expected-error {{cannot form pointer to deduced class template specialization type}}
26
27 }
28
29 namespace GH64347 {
30
31 template<typename X, typename Y> struct A { X x; Y y;};
32 void test() {
33 A(1, 2);
34 new A(1, 2);
35 }
36
37 template<A a>
38 void f() { (void)a; }
39 void k() {
40 // Test CTAD works for non-type template arguments.
41 f<A(0, 0)>();
42 }
43
44 } // namespace GH64347
45
46 namespace GH123591 {
47
48
49 template < typename... _Types >
50 struct variant {
51 template <int N = sizeof...(_Types)>
52 variant(_Types...);
53 };
54
55 template <class T>
56 using AstNode = variant<T, T, T>;
57
58 AstNode tree(42, 43, 44);
59
60 }
61
62 namespace GH123591_2 {
63
64 template <int>
65 using enable_if_t = char;
66
67 template < typename... Types >
68 struct variant {
69 template < enable_if_t<sizeof...(Types)>>
70 variant();
71 };
72
73 template <int>
74 using AstNode = variant<>;
75 // expected-note@-1 {{couldn't infer template argument ''}} \
76 // expected-note@-1 2{{implicit deduction guide declared as}} \
77 // expected-note@-1 {{candidate function template not viable}}
78
79
80 AstNode tree; // expected-error {{no viable constructor or deduction guide}}
81
82 }
83
84 namespace GH127539 {
85
86 template <class...>
87 struct A {
88 template <class... ArgTs>
89 A(ArgTs...) {}
90 };
91
92 template <class... ArgTs>
93 A(ArgTs...) -> A<typename ArgTs::value_type...>;
94
95 template <class... Ts>
96 using AA = A<Ts..., Ts...>;
97
98 AA a{};
99
100 }
101
102 namespace GH129077 {
103
104 using size_t = decltype(sizeof(0));
105
106 struct index_type
107 {
108 size_t value = 0;
109 index_type() = default;
110 constexpr index_type(size_t i) noexcept : value(i) {}
111 };
112
113 template <index_type... Extents>
114 struct extents
115 {
116 constexpr extents(decltype(Extents)...) noexcept {}
117 };
118
119 template <class... Extents>
120 extents(Extents...) -> extents<(requires { Extents::value; } ? Extents{} : ~0ull)...>;
121
122 template <index_type... Index>
123 using index = extents<Index...>;
124
125 int main()
126 {
127 extents i{0,0};
128 auto j = extents<64,{}>({}, 42);
129
130 index k{0,0};
131 auto l = index<64,{}>({}, 42);
132
133 return 0;
134 }
135
136 }
137
138 namespace GH129620 {
139
140 template <class... Ts>
141 struct A {
142 constexpr A(Ts...) {}
143 };
144
145 template <class... Ts>
146 using Foo = A<Ts...>;
147
148 template <class T>
149 using Bar = Foo<T, T>;
150
151 Bar a{0, 0};
152
153 }
154
155 namespace GH129998 {
156
157 struct converible_to_one {
158 constexpr operator int() const noexcept { return 1; }
159 };
160
161 template <int... Extents>
162 struct class_template {
163 class_template() = default;
164 constexpr class_template(auto&&...) noexcept {}
165 };
166
167 template <class... Extents>
168 class_template(Extents...) -> class_template<(true ? 0 : +Extents{})...>;
169
170 template <int... Extents>
171 using alias_template = class_template<Extents...>;
172
173 alias_template var2{converible_to_one{}, 2};
174
175 }
176
177 namespace GH136624 {
178 // expected-note@+1 2{{no known conversion}}
179 template<typename U> struct A {
180 U t;
181 };
182
183 template<typename V> A(V) -> A<V>;
184
185 namespace foo {
186 template<class Y> using Alias = A<Y>;
187 }
188
189 // FIXME: This diagnostic is missing 'foo::Alias', as written.
190 foo::Alias t = 0;
191 // expected-error@-1 {{no viable conversion from 'int' to 'GH136624::A<int>' (aka 'A<int>')}}
192 } // namespace GH136624
193
194 namespace GH131342 {
195 template <class> constexpr int val{0};
196 template <class T, int> struct A { A(T) {} };
197 template <class T> using AA = A<T, val<T>>;
198 AA a{0};
199 } // namespace GH131342