| 1 |
// RUN: %clang_cc1 -std=c++2a -verify -ast-dump -ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s --strict-whitespace |
| 2 |
|
| 3 |
template<auto ...> struct X {}; |
| 4 |
template<template<typename X, X> typename> struct Y {}; |
| 5 |
template<typename ...> struct Z {}; |
| 6 |
|
| 7 |
template<typename T, typename ...Ts> struct A { |
| 8 |
template<Ts ...Ns, T *...Ps> A(X<Ps...>, Ts (*...qs)[Ns]); |
| 9 |
}; |
| 10 |
int arr1[3], arr2[3]; |
| 11 |
short arr3[4]; |
| 12 |
A a(X<&arr1, &arr2>{}, &arr1, &arr2, &arr3); |
| 13 |
using AT = decltype(a); |
| 14 |
using AT = A<int[3], int, int, short>; |
| 15 |
|
| 16 |
// CHECK-LABEL: Dumping <deduction guide for A>: |
| 17 |
// CHECK: FunctionTemplateDecl |
| 18 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T |
| 19 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 ... Ts |
| 20 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'Ts...' depth 0 index 2 ... Ns |
| 21 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'T *' depth 0 index 3 ... Ps |
| 22 |
// CHECK: |-CXXDeductionGuideDecl |
| 23 |
// CHECK: | |-ParmVarDecl {{.*}} 'X<Ps...>' |
| 24 |
// CHECK: | `-ParmVarDecl {{.*}} 'Ts (*)[Ns]...' pack |
| 25 |
// CHECK: `-CXXDeductionGuideDecl |
| 26 |
// CHECK: |-TemplateArgument type 'int[3]' |
| 27 |
// CHECK: |-TemplateArgument pack |
| 28 |
// CHECK: | |-TemplateArgument type 'int' |
| 29 |
// CHECK: | |-TemplateArgument type 'int' |
| 30 |
// CHECK: | `-TemplateArgument type 'short' |
| 31 |
// CHECK: |-TemplateArgument pack |
| 32 |
// CHECK: | |-TemplateArgument integral '3' |
| 33 |
// CHECK: | |-TemplateArgument integral '3' |
| 34 |
// CHECK: | `-TemplateArgument integral '(short)4' |
| 35 |
// CHECK: |-TemplateArgument pack |
| 36 |
// CHECK: | |-TemplateArgument decl |
| 37 |
// CHECK: | | `-Var {{.*}} 'arr1' 'int[3]' |
| 38 |
// CHECK: | `-TemplateArgument decl |
| 39 |
// CHECK: | `-Var {{.*}} 'arr2' 'int[3]' |
| 40 |
// CHECK: |-ParmVarDecl {{.*}} 'X<&arr1, &arr2>' |
| 41 |
// CHECK: |-ParmVarDecl {{.*}} 'int (*)[3]' |
| 42 |
// CHECK: |-ParmVarDecl {{.*}} 'int (*)[3]' |
| 43 |
// CHECK: `-ParmVarDecl {{.*}} 'short (*)[4]' |
| 44 |
// CHECK: FunctionProtoType {{.*}} 'auto (X<Ps...>, Ts (*)[Ns]...) -> A<T, Ts...>' dependent trailing_return |
| 45 |
// CHECK: |-InjectedClassNameType {{.*}} 'A<T, Ts...>' dependent |
| 46 |
// CHECK: |-TemplateSpecializationType {{.*}} 'X<Ps...>' dependent |
| 47 |
// CHECK: | `-TemplateArgument expr |
| 48 |
// CHECK: | `-PackExpansionExpr {{.*}} 'T *' |
| 49 |
// CHECK: | `-DeclRefExpr {{.*}} 'T *' NonTypeTemplateParm {{.*}} 'Ps' 'T *' |
| 50 |
// CHECK: `-PackExpansionType {{.*}} 'Ts (*)[Ns]...' dependent |
| 51 |
// CHECK: `-PointerType {{.*}} 'Ts (*)[Ns]' dependent contains_unexpanded_pack |
| 52 |
// CHECK: `-ParenType {{.*}} 'Ts[Ns]' sugar dependent contains_unexpanded_pack |
| 53 |
// CHECK: `-DependentSizedArrayType {{.*}} 'Ts[Ns]' dependent contains_unexpanded_pack |
| 54 |
// CHECK: |-TemplateTypeParmType {{.*}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack |
| 55 |
// CHECK: | `-TemplateTypeParm {{.*}} 'Ts' |
| 56 |
// CHECK: `-DeclRefExpr {{.*}} 'Ts' NonTypeTemplateParm {{.*}} 'Ns' 'Ts...' |
| 57 |
|
| 58 |
template<typename T, T V> struct B { |
| 59 |
template<typename U, U W> B(X<W, V>); |
| 60 |
}; |
| 61 |
B b(X<nullptr, 'x'>{}); |
| 62 |
using BT = decltype(b); |
| 63 |
using BT = B<char, 'x'>; |
| 64 |
|
| 65 |
// CHECK-LABEL: Dumping <deduction guide for B>: |
| 66 |
// CHECK: FunctionTemplateDecl |
| 67 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T |
| 68 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'T' depth 0 index 1 V |
| 69 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U |
| 70 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'U' depth 0 index 3 W |
| 71 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (X<W, V>) -> B<T, V>' |
| 72 |
// CHECK: | `-ParmVarDecl {{.*}} 'X<W, V>' |
| 73 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (X<nullptr, 'x'>) -> B<char, 'x'>' |
| 74 |
// CHECK: |-TemplateArgument type 'char' |
| 75 |
// CHECK: |-TemplateArgument integral ''x'' |
| 76 |
// CHECK: |-TemplateArgument type 'std::nullptr_t' |
| 77 |
// CHECK: |-TemplateArgument nullptr |
| 78 |
// CHECK: `-ParmVarDecl {{.*}} 'X<nullptr, 'x'>' |
| 79 |
// CHECK: FunctionProtoType {{.*}} 'auto (X<W, V>) -> B<T, V>' dependent trailing_return |
| 80 |
// CHECK: |-InjectedClassNameType {{.*}} 'B<T, V>' dependent |
| 81 |
// CHECK: `-TemplateSpecializationType {{.*}} 'X<W, V>' dependent |
| 82 |
// CHECK: |-TemplateArgument expr |
| 83 |
// CHECK: | `-DeclRefExpr {{.*}} 'U' NonTypeTemplateParm {{.*}} 'W' 'U' |
| 84 |
// CHECK: `-TemplateArgument expr |
| 85 |
// CHECK: `-DeclRefExpr {{.*}} 'T' NonTypeTemplateParm {{.*}} 'V' 'T' |
| 86 |
|
| 87 |
template<typename A> struct C { |
| 88 |
template<template<typename X, X> typename T, typename U, U V = 0> C(A, Y<T>, U); |
| 89 |
}; |
| 90 |
C c(1, Y<B>{}, 2); |
| 91 |
using CT = decltype(c); |
| 92 |
using CT = C<int>; |
| 93 |
|
| 94 |
// CHECK-LABEL: Dumping <deduction guide for C>: |
| 95 |
// CHECK: FunctionTemplateDecl |
| 96 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 A |
| 97 |
// CHECK: |-TemplateTemplateParmDecl {{.*}} depth 0 index 1 T |
| 98 |
// CHECK: | |-TemplateTypeParmDecl {{.*}} typename depth 1 index 0 X |
| 99 |
// CHECK: | `-NonTypeTemplateParmDecl {{.*}} 'X' depth 1 index 1 |
| 100 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U |
| 101 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'U' depth 0 index 3 V |
| 102 |
// CHECK: | `-TemplateArgument {{.*}} expr |
| 103 |
// CHECK: | `-IntegerLiteral {{.*}} 'int' 0 |
| 104 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y<T>, U) -> C<A>' |
| 105 |
// CHECK: | |-ParmVarDecl {{.*}} 'A' |
| 106 |
// CHECK: | |-ParmVarDecl {{.*}} 'Y<T>' |
| 107 |
// CHECK: | `-ParmVarDecl {{.*}} 'U' |
| 108 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int, Y<B>, int) -> C<int>' |
| 109 |
// CHECK: |-TemplateArgument type 'int' |
| 110 |
// CHECK: |-TemplateArgument template 'B' |
| 111 |
// CHECK: |-TemplateArgument type 'int' |
| 112 |
// CHECK: |-TemplateArgument integral '0' |
| 113 |
// CHECK: |-ParmVarDecl {{.*}} 'int' |
| 114 |
// CHECK: |-ParmVarDecl {{.*}} 'Y<B>' |
| 115 |
// CHECK: `-ParmVarDecl {{.*}} 'int' |
| 116 |
// CHECK: FunctionProtoType {{.*}} 'auto (A, Y<T>, U) -> C<A>' dependent trailing_return cdecl |
| 117 |
// CHECK: |-InjectedClassNameType {{.*}} 'C<A>' dependent |
| 118 |
// CHECK: |-TemplateTypeParmType {{.*}} 'A' dependent depth 0 index 0 |
| 119 |
// CHECK: | `-TemplateTypeParm {{.*}} 'A' |
| 120 |
// CHECK: |-TemplateSpecializationType {{.*}} 'Y<T>' dependent |
| 121 |
// CHECK: | `-TemplateArgument template |
| 122 |
// CHECK: `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2 |
| 123 |
|
| 124 |
template<typename ...T> struct D { // expected-note {{candidate}} \ |
| 125 |
// expected-note {{implicit deduction guide declared as 'template <typename ...T> D(D<T...>) -> D<T...>'}} |
| 126 |
template<typename... U> using B = int(int (*...p)(T, U)); |
| 127 |
template<typename U1, typename U2> D(B<U1, U2>*); // expected-note {{candidate}} \ |
| 128 |
// expected-note {{implicit deduction guide declared as 'template <typename ...T, typename U1, typename U2> D(B<U1, U2> *) -> D<T...>'}} |
| 129 |
}; |
| 130 |
int f(int(int, int), int(int, int)); |
| 131 |
// FIXME: We can't deduce this because we can't deduce through a |
| 132 |
// SubstTemplateTypeParmPackType. |
| 133 |
D d = f; // expected-error {{no viable}} |
| 134 |
using DT = decltype(d); |
| 135 |
using DT = D<int, int>; |
| 136 |
|
| 137 |
// CHECK-LABEL: Dumping <deduction guide for D>: |
| 138 |
// CHECK: FunctionTemplateDecl |
| 139 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 ... T |
| 140 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U1 |
| 141 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U2 |
| 142 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (B<U1, U2> *) -> D<T...>' |
| 143 |
// CHECK: `-ParmVarDecl {{.*}} 'B<U1, U2> *' |
| 144 |
// CHECK: FunctionProtoType {{.*}} 'auto (B<U1, U2> *) -> D<T...>' dependent trailing_return |
| 145 |
// CHECK: |-InjectedClassNameType {{.*}} 'D<T...>' dependent |
| 146 |
// CHECK: `-PointerType {{.*}} 'B<U1, U2> *' dependent |
| 147 |
// CHECK: `-TemplateSpecializationType {{.*}} 'B<U1, U2>' sugar dependent alias |
| 148 |
// CHECK: |-TemplateArgument type 'U1' |
| 149 |
// CHECK: |-TemplateArgument type 'U2' |
| 150 |
// CHECK: `-FunctionProtoType {{.*}} 'int (int (*)(T, U)...)' dependent cdecl |
| 151 |
// CHECK: |-BuiltinType {{.*}} 'int' |
| 152 |
// CHECK: `-PackExpansionType {{.*}} 'int (*)(T, U)...' dependent expansions 2 |
| 153 |
// CHECK: `-PointerType {{.*}} 'int (*)(T, U)' dependent contains_unexpanded_pack |
| 154 |
// CHECK: `-ParenType {{.*}} 'int (T, U)' sugar dependent contains_unexpanded_pack |
| 155 |
// CHECK: `-FunctionProtoType {{.*}} 'int (T, U)' dependent contains_unexpanded_pack cdecl |
| 156 |
// CHECK: |-BuiltinType {{.*}} 'int' |
| 157 |
// CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack |
| 158 |
// CHECK: | `-TemplateTypeParm {{.*}} 'T' |
| 159 |
// CHECK: `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U |
| 160 |
// CHECK: |-TypeAliasTemplate {{.*}} 'B' |
| 161 |
// CHECK: `-TemplateArgument pack |
| 162 |
// CHECK: |-TemplateArgument type 'U1':'type-parameter-0-1' |
| 163 |
// CHECK-NOT: Subst |
| 164 |
// CHECK: | `-TemplateTypeParmType |
| 165 |
// CHECK: `-TemplateArgument type 'U2':'type-parameter-0-2' |
| 166 |
// CHECK-NOT: Subst |
| 167 |
// CHECK: `-TemplateTypeParmType |
| 168 |
|
| 169 |
template<int ...N> struct E { // expected-note {{candidate}} \ |
| 170 |
expected-note {{implicit deduction guide declared as 'template <int ...N> E(E<N...>) -> E<N...>'}} |
| 171 |
template<int ...M> using B = Z<X<N, M>...>; |
| 172 |
template<int M1, int M2> E(B<M1, M2>); // expected-note {{candidate}} \ |
| 173 |
// expected-note {{implicit deduction guide declared as 'template <int ...N, int M1, int M2> E(B<M1, M2>) -> E<N...>'}}}} |
| 174 |
}; |
| 175 |
// FIXME: We can't deduce this because we can't deduce through a |
| 176 |
// SubstNonTypeTemplateParmPackExpr. |
| 177 |
E e = Z<X<1, 2>, X<3, 4>>(); // expected-error {{no viable}} |
| 178 |
using ET = decltype(e); |
| 179 |
using ET = E<1, 3>; |
| 180 |
|
| 181 |
// CHECK-LABEL: Dumping <deduction guide for E>: |
| 182 |
// CHECK: FunctionTemplateDecl |
| 183 |
// CHECK: |-NonTypeTemplateParmDecl [[N:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 0 ... N |
| 184 |
// CHECK: |-NonTypeTemplateParmDecl [[M1:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 1 M1 |
| 185 |
// CHECK: |-NonTypeTemplateParmDecl [[M2:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 2 M2 |
| 186 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (B<M1, M2>) -> E<N...>' |
| 187 |
// CHECK: `-ParmVarDecl {{.*}} 'B<M1, M2>':'Z<X<N, M>...>' |
| 188 |
// CHECK: FunctionProtoType {{.*}} 'auto (B<M1, M2>) -> E<N...>' dependent trailing_return |
| 189 |
// CHECK: |-InjectedClassNameType {{.*}} 'E<N...>' dependent |
| 190 |
// CHECK: `-TemplateSpecializationType {{.*}} 'B<M1, M2>' sugar dependent alias |
| 191 |
// CHECK: |-TemplateArgument expr |
| 192 |
// CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'M1' 'int' |
| 193 |
// CHECK: |-TemplateArgument expr |
| 194 |
// CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'M2' 'int' |
| 195 |
// CHECK: `-TemplateSpecializationType {{.*}} 'Z<X<N, M>...>' dependent |
| 196 |
// CHECK: `-TemplateArgument type 'X<N, M>...' |
| 197 |
// CHECK: `-PackExpansionType {{.*}} 'X<N, M>...' dependent expansions 2 |
| 198 |
// CHECK: `-TemplateSpecializationType {{.*}} 'X<N, M>' dependent contains_unexpanded_pack |
| 199 |
// CHECK: |-TemplateArgument expr |
| 200 |
// CHECK-NOT: Subst |
| 201 |
// CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[N]] 'N' 'int' |
| 202 |
// CHECK: `-TemplateArgument expr |
| 203 |
// CHECK: `-SubstNonTypeTemplateParmPackExpr {{.*}} 'int' |
| 204 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 1 index 0 ... M |
| 205 |
// CHECK: `-TemplateArgument pack |
| 206 |
// CHECK: |-TemplateArgument expr |
| 207 |
// CHECK-NOT: Subst |
| 208 |
// CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M1]] 'M1' 'int' |
| 209 |
// CHECK: `-TemplateArgument expr |
| 210 |
// CHECK-NOT: Subst |
| 211 |
// CHECK: `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M2]] 'M2' 'int' |
| 212 |
|
| 213 |
template <char = 'x'> struct F; |
| 214 |
|
| 215 |
template <char> struct F { |
| 216 |
template <typename U> |
| 217 |
requires(false) F(U); |
| 218 |
template <typename U> |
| 219 |
requires(true) F(U); |
| 220 |
}; |
| 221 |
|
| 222 |
F s(0); |
| 223 |
|
| 224 |
// CHECK-LABEL: Dumping <deduction guide for F>: |
| 225 |
// CHECK: FunctionTemplateDecl |
| 226 |
// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0 |
| 227 |
// CHECK: `-TemplateArgument {{.*}} expr |
| 228 |
// CHECK: | |-inherited from NonTypeTemplateParm {{.*}} depth 0 index 0 'char' |
| 229 |
// CHECK: | `-CharacterLiteral {{.*}} 'char' 120 |
| 230 |
// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U |
| 231 |
// CHECK: |-ParenExpr {{.*}} 'bool' |
| 232 |
// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false |
| 233 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (U) -> F<value-parameter-0-0>' |
| 234 |
// CHECK: | `-ParmVarDecl {{.*}} 'U' |
| 235 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for F> 'auto (int) -> F<>' |
| 236 |
// CHECK: |-TemplateArgument integral ''x'' |
| 237 |
// CHECK: |-TemplateArgument type 'int' |
| 238 |
// CHECK: | `-BuiltinType {{.*}} 'int' |
| 239 |
// CHECK: `-ParmVarDecl {{.*}} 'int' |
| 240 |
// CHECK: FunctionProtoType {{.*}} 'auto (U) -> F<value-parameter-0-0>' dependent trailing_return cdecl |
| 241 |
// CHECK: |-InjectedClassNameType {{.*}} 'F<value-parameter-0-0>' dependent |
| 242 |
// CHECK: | `-CXXRecord {{.*}} 'F' |
| 243 |
// CHECK: `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 1 |
| 244 |
|
| 245 |
template<typename T> |
| 246 |
struct G { T t; }; |
| 247 |
|
| 248 |
G g = {1}; |
| 249 |
// CHECK-LABEL: Dumping <deduction guide for G>: |
| 250 |
// CHECK: FunctionTemplateDecl |
| 251 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for G> 'auto (T) -> G<T>' aggregate |
| 252 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for G> 'auto (int) -> G<int>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 253 |
|
| 254 |
template<typename X> |
| 255 |
using AG = G<X>; |
| 256 |
AG ag = {1}; |
| 257 |
// Verify that the aggregate deduction guide for alias templates is built. |
| 258 |
// CHECK-LABEL: Dumping <deduction guide for AG> |
| 259 |
// CHECK: FunctionTemplateDecl |
| 260 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (X) -> G<X>' |
| 261 |
// CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int) -> G<int>' implicit_instantiation |
| 262 |
// CHECK: |-TemplateArgument type 'int' |
| 263 |
// CHECK: | `-BuiltinType {{.*}} 'int' |
| 264 |
// CHECK: `-ParmVarDecl {{.*}} 'int' |
| 265 |
|
| 266 |
template <typename X = int> |
| 267 |
using BG = G<int>; |
| 268 |
BG bg(1.0); |
| 269 |
// CHECK-LABEL: Dumping <deduction guide for BG> |
| 270 |
// CHECK: FunctionTemplateDecl {{.*}} implicit <deduction guide for BG> |
| 271 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (int) -> G<int>' aggregate |
| 272 |
|
| 273 |
template <typename D> |
| 274 |
requires (sizeof(D) == 4) |
| 275 |
struct Foo { |
| 276 |
Foo(D); |
| 277 |
}; |
| 278 |
|
| 279 |
template <typename U> |
| 280 |
using AFoo = Foo<G<U>>; |
| 281 |
// Verify that the require-clause from the Foo deduction guide is transformed. |
| 282 |
// The D occurrence should be rewritten to G<U>. |
| 283 |
// |
| 284 |
// CHECK-LABEL: Dumping <deduction guide for AFoo> |
| 285 |
// CHECK: FunctionTemplateDecl {{.*}} implicit <deduction guide for AFoo> |
| 286 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 U |
| 287 |
// CHECK-NEXT: |-BinaryOperator {{.*}} '&&' |
| 288 |
// CHECK-NEXT: | |-ParenExpr {{.*}} 'bool' |
| 289 |
// CHECK-NEXT: | | `-BinaryOperator {{.*}} 'bool' '==' |
| 290 |
// CHECK-NEXT: | | |-UnaryExprOrTypeTraitExpr {{.*}} 'G<U>' |
| 291 |
// CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} |
| 292 |
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} |
| 293 |
// CHECK-NEXT: | `-TypeTraitExpr {{.*}} 'bool' __is_deducible |
| 294 |
// CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.*}} 'AFoo' dependent |
| 295 |
// CHECK-NEXT: | | `-name: 'AFoo' |
| 296 |
// CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.+}} AFoo |
| 297 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.*}} 'Foo<G<U>>' dependent |
| 298 |
// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for AFoo> 'auto (G<U>) -> Foo<G<U>>' |
| 299 |
// CHECK-NEXT: | `-ParmVarDecl {{.*}} 'G<U>' |
| 300 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for AFoo> 'auto (G<int>) -> Foo<G<int>>' implicit_instantiation |
| 301 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 302 |
// CHECK-NEXT: | `-BuiltinType {{.*}} 'int' |
| 303 |
// CHECK-NEXT: `-ParmVarDecl {{.*}} 'G<int>' |
| 304 |
|
| 305 |
AFoo aa(G<int>{}); |
| 306 |
|
| 307 |
namespace TTP { |
| 308 |
template<typename> struct A {}; |
| 309 |
|
| 310 |
template<class T> struct B { |
| 311 |
template<template <class> typename TT> B(TT<T>); |
| 312 |
}; |
| 313 |
|
| 314 |
B b(A<int>{}); |
| 315 |
} // namespace TTP |
| 316 |
|
| 317 |
// CHECK-LABEL: Dumping TTP::<deduction guide for B>: |
| 318 |
// CHECK-NEXT: FunctionTemplateDecl 0x{{.+}} <{{.+}}:[[# @LINE - 7]]:5, col:51> |
| 319 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T{{$}} |
| 320 |
// CHECK-NEXT: |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 TT{{$}} |
| 321 |
// CHECK-NEXT: | `-TemplateTypeParmDecl {{.+}} class depth 1 index 0{{$}} |
| 322 |
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.+}} 'auto (TT<T>) -> TTP::B<T>'{{$}} |
| 323 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} 'TT<T>'{{$}} |
| 324 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} 'auto (TTP::A<int>) -> TTP::B<int>' |
| 325 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 326 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int'{{$}} |
| 327 |
// CHECK-NEXT: |-TemplateArgument template 'TTP::A'{{$}} |
| 328 |
// CHECK-NEXT: | `-ClassTemplateDecl {{.+}} A{{$}} |
| 329 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} 'TTP::A<int>'{{$}} |
| 330 |
// CHECK-NEXT: FunctionProtoType {{.+}} 'auto (TT<T>) -> TTP::B<T>' dependent trailing_return cdecl{{$}} |
| 331 |
// CHECK-NEXT: |-InjectedClassNameType {{.+}} 'TTP::B<T>' dependent{{$}} |
| 332 |
// CHECK-NEXT: | `-CXXRecord {{.+}} 'B'{{$}} |
| 333 |
// CHECK-NEXT: `-TemplateSpecializationType {{.+}} 'TT<T>' dependent{{$}} |
| 334 |
// CHECK-NEXT: |-name: 'TT':'template-parameter-0-1' |
| 335 |
// CHECK-NEXT: | `-TemplateTemplateParmDecl {{.+}} depth 0 index 1 |
| 336 |
// CHECK-NEXT: `-TemplateArgument type 'T':'type-parameter-0-0'{{$}} |
| 337 |
// CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0{{$}} |
| 338 |
// CHECK-NEXT: `-TemplateTypeParm {{.+}} 'T'{{$}} |
| 339 |
|
| 340 |
namespace GH64625 { |
| 341 |
|
| 342 |
template <class T> struct X { |
| 343 |
T t[2]; |
| 344 |
}; |
| 345 |
|
| 346 |
X x = {{1, 2}}; |
| 347 |
|
| 348 |
// CHECK-LABEL: Dumping GH64625::<deduction guide for X>: |
| 349 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} <{{.+}}:[[#@LINE - 7]]:1, col:27> col:27 implicit <deduction guide for X> |
| 350 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} <col:11, col:17> col:17 referenced class depth 0 index 0 T |
| 351 |
// CHECK: |-CXXDeductionGuideDecl {{.+}} <col:27> col:27 implicit <deduction guide for X> 'auto (T (&&)[2]) -> GH64625::X<T>' aggregate |
| 352 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:27> col:27 'T (&&)[2]' |
| 353 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:27> col:27 implicit used <deduction guide for X> 'auto (int (&&)[2]) -> GH64625::X<int>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 354 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 355 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 356 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} <col:27> col:27 'int (&&)[2]' |
| 357 |
// CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T (&&)[2]) -> GH64625::X<T>' dependent trailing_return |
| 358 |
// CHECK-NEXT: |-InjectedClassNameType {{.+}} 'GH64625::X<T>' dependent |
| 359 |
// CHECK-NEXT: | `-CXXRecord {{.+}} 'X' |
| 360 |
// CHECK-NEXT: `-RValueReferenceType {{.+}} 'T (&&)[2]' dependent |
| 361 |
// CHECK-NEXT: `-ConstantArrayType {{.+}} 'T[2]' dependent 2 |
| 362 |
// CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0 |
| 363 |
// CHECK-NEXT: `-TemplateTypeParm {{.+}} 'T' |
| 364 |
|
| 365 |
template <class T, class U> struct TwoArrays { |
| 366 |
T t[2]; |
| 367 |
U u[3]; |
| 368 |
}; |
| 369 |
|
| 370 |
TwoArrays ta = {{1, 2}, {3, 4, 5}}; |
| 371 |
// CHECK-LABEL: Dumping GH64625::<deduction guide for TwoArrays>: |
| 372 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} <{{.+}}:[[#@LINE - 7]]:1, col:36> col:36 implicit <deduction guide for TwoArrays> |
| 373 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} <col:11, col:17> col:17 referenced class depth 0 index 0 T |
| 374 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} <col:20, col:26> col:26 referenced class depth 0 index 1 U |
| 375 |
// CHECK: |-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit <deduction guide for TwoArrays> 'auto (T (&&)[2], U (&&)[3]) -> GH64625::TwoArrays<T, U>' aggregate |
| 376 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T (&&)[2]' |
| 377 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:36> col:36 'U (&&)[3]' |
| 378 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit used <deduction guide for TwoArrays> 'auto (int (&&)[2], int (&&)[3]) -> GH64625::TwoArrays<int, int>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 379 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 380 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 381 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 382 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 383 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[2]' |
| 384 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[3]' |
| 385 |
// CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T (&&)[2], U (&&)[3]) -> GH64625::TwoArrays<T, U>' dependent trailing_return |
| 386 |
// CHECK-NEXT: |-InjectedClassNameType {{.+}} 'GH64625::TwoArrays<T, U>' dependent |
| 387 |
// CHECK-NEXT: | `-CXXRecord {{.+}} 'TwoArrays' |
| 388 |
// CHECK-NEXT: |-RValueReferenceType {{.+}} 'T (&&)[2]' dependent |
| 389 |
// CHECK-NEXT: | `-ConstantArrayType {{.+}} 'T[2]' dependent 2 |
| 390 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0 |
| 391 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T' |
| 392 |
// CHECK-NEXT: `-RValueReferenceType {{.+}} 'U (&&)[3]' dependent |
| 393 |
// CHECK-NEXT: `-ConstantArrayType {{.+}} 'U[3]' dependent 3 |
| 394 |
// CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 395 |
// CHECK-NEXT: `-TemplateTypeParm {{.+}} 'U' |
| 396 |
|
| 397 |
TwoArrays tb = {1, 2, {3, 4, 5}}; |
| 398 |
// CHECK: |-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit <deduction guide for TwoArrays> 'auto (T, T, U (&&)[3]) -> GH64625::TwoArrays<T, U>' aggregate |
| 399 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T' |
| 400 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T' |
| 401 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:36> col:36 'U (&&)[3]' |
| 402 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit used <deduction guide for TwoArrays> 'auto (int, int, int (&&)[3]) -> GH64625::TwoArrays<int, int>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 403 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 404 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 405 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 406 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 407 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int' |
| 408 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int' |
| 409 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[3]' |
| 410 |
// CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T, T, U (&&)[3]) -> GH64625::TwoArrays<T, U>' dependent trailing_return |
| 411 |
// CHECK-NEXT: |-InjectedClassNameType {{.+}} 'GH64625::TwoArrays<T, U>' dependent |
| 412 |
// CHECK-NEXT: | `-CXXRecord {{.+}} 'TwoArrays' |
| 413 |
// CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0 |
| 414 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T' |
| 415 |
// CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0 |
| 416 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T' |
| 417 |
// CHECK-NEXT: `-RValueReferenceType {{.+}} 'U (&&)[3]' dependent |
| 418 |
// CHECK-NEXT: `-ConstantArrayType {{.+}} 'U[3]' dependent 3 |
| 419 |
// CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 420 |
// CHECK-NEXT: `-TemplateTypeParm {{.+}} 'U' |
| 421 |
|
| 422 |
TwoArrays tc = {{1, 2}, 3, 4, 5}; |
| 423 |
// CHECK: |-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit <deduction guide for TwoArrays> 'auto (T (&&)[2], U, U, U) -> GH64625::TwoArrays<T, U>' aggregate |
| 424 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T (&&)[2]' |
| 425 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'U' |
| 426 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'U' |
| 427 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:36> col:36 'U' |
| 428 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit used <deduction guide for TwoArrays> 'auto (int (&&)[2], int, int, int) -> GH64625::TwoArrays<int, int>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 429 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 430 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 431 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 432 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 433 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[2]' |
| 434 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int' |
| 435 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int' |
| 436 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} <col:36> col:36 'int' |
| 437 |
// CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T (&&)[2], U, U, U) -> GH64625::TwoArrays<T, U>' dependent trailing_return |
| 438 |
// CHECK-NEXT: |-InjectedClassNameType {{.+}} 'GH64625::TwoArrays<T, U>' dependent |
| 439 |
// CHECK-NEXT: | `-CXXRecord {{.+}} 'TwoArrays' |
| 440 |
// CHECK-NEXT: |-RValueReferenceType {{.+}} 'T (&&)[2]' dependent |
| 441 |
// CHECK-NEXT: | `-ConstantArrayType {{.+}} 'T[2]' dependent 2 |
| 442 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0 |
| 443 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T' |
| 444 |
// CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 445 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'U' |
| 446 |
// CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 447 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'U' |
| 448 |
// CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 449 |
// CHECK-NEXT: `-TemplateTypeParm {{.+}} 'U' |
| 450 |
|
| 451 |
} // namespace GH64625 |
| 452 |
|
| 453 |
namespace GH83368 { |
| 454 |
|
| 455 |
template <int N> struct A { |
| 456 |
int f1[N]; |
| 457 |
}; |
| 458 |
|
| 459 |
A a{.f1 = {1}}; |
| 460 |
|
| 461 |
// CHECK-LABEL: Dumping GH83368::<deduction guide for A>: |
| 462 |
// CHECK-NEXT: FunctionTemplateDecl 0x{{.+}} <{{.+}}:[[#@LINE - 7]]:1, col:25> col:25 implicit <deduction guide for A> |
| 463 |
// CHECK-NEXT: |-NonTypeTemplateParmDecl {{.+}} <col:11, col:15> col:15 referenced 'int' depth 0 index 0 N |
| 464 |
// CHECK: |-CXXDeductionGuideDecl {{.+}} <col:25> col:25 implicit <deduction guide for A> 'auto (int (&&)[N]) -> GH83368::A<N>' aggregate |
| 465 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:25> col:25 'int (&&)[N]' |
| 466 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:25> col:25 implicit used <deduction guide for A> 'auto (int (&&)[1]) -> GH83368::A<1>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 467 |
// CHECK-NEXT: |-TemplateArgument integral '1' |
| 468 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} <col:25> col:25 'int (&&)[1]' |
| 469 |
// CHECK-NEXT: FunctionProtoType {{.+}} 'auto (int (&&)[N]) -> GH83368::A<N>' dependent trailing_return |
| 470 |
// CHECK-NEXT: |-InjectedClassNameType {{.+}} 'GH83368::A<N>' dependent |
| 471 |
// CHECK-NEXT: | `-CXXRecord {{.+}} 'A' |
| 472 |
// CHECK-NEXT: `-RValueReferenceType {{.+}} 'int (&&)[N]' dependent |
| 473 |
// CHECK-NEXT: `-DependentSizedArrayType {{.+}} 'int[N]' dependent |
| 474 |
// CHECK-NEXT: |-BuiltinType {{.+}} 'int' |
| 475 |
// CHECK-NEXT: `-DeclRefExpr {{.+}} <{{.+}}:10> 'int' NonTypeTemplateParm {{.+}} 'N' 'int' |
| 476 |
|
| 477 |
} // namespace GH83368 |
| 478 |
|
| 479 |
namespace GH60777 { |
| 480 |
|
| 481 |
template <typename... Ts> constexpr bool True() { return true; } |
| 482 |
|
| 483 |
template <typename T> |
| 484 |
requires(sizeof(T) > 1) |
| 485 |
struct A { |
| 486 |
template <typename... Ts> |
| 487 |
requires(sizeof...(Ts) == 0) |
| 488 |
A(T val, Ts... tail) |
| 489 |
requires(True<Ts...>()) |
| 490 |
{} |
| 491 |
}; |
| 492 |
|
| 493 |
A a(42); |
| 494 |
|
| 495 |
// `requires (sizeof(T) > 1)` goes into the deduction guide together with |
| 496 |
// `requires (True<Ts...>())`, while `requires(sizeof...(Ts) == 0)` goes into |
| 497 |
// the template parameter list of the synthesized declaration. |
| 498 |
|
| 499 |
// CHECK-LABEL: Dumping GH60777::<deduction guide for A>: |
| 500 |
// CHECK-NEXT: FunctionTemplateDecl 0x{{.+}} <{{.+}}> {{.+}} implicit <deduction guide for A> |
| 501 |
// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} <{{.+}}> col:20 referenced typename depth 0 index 0 T |
| 502 |
// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} <{{.+}}> col:25 typename depth 0 index 1 ... Ts |
| 503 |
// CHECK-NEXT: |-ParenExpr 0x{{.+}} <{{.+}}> 'bool' |
| 504 |
// CHECK-NEXT: | `-BinaryOperator 0x{{.+}} <{{.+}}> 'bool' '==' |
| 505 |
// CHECK-NEXT: | |-SizeOfPackExpr {{.+}} Ts |
| 506 |
// CHECK-NEXT: | | `-TemplateArgument type 'Ts...':'type-parameter-0-1...' |
| 507 |
// CHECK-NEXT: | | `-PackExpansionType 0x{{.+}} 'Ts...' dependent |
| 508 |
// CHECK-NEXT: | | `-TemplateTypeParmType 0x{{.+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack |
| 509 |
// CHECK-NEXT: | | `-TemplateTypeParm 0x{{.+}} 'Ts' |
| 510 |
// CHECK-NEXT: | `-ImplicitCastExpr {{.+}} <IntegralCast> |
| 511 |
// CHECK-NEXT: | `-IntegerLiteral 0x{{.+}} <{{.+}}> 'int' 0 |
| 512 |
// CHECK-NEXT: |-CXXDeductionGuideDecl 0x{{.+}} <{{.+}}> line:{{.+}} implicit <deduction guide for A> 'auto (T, Ts...) -> GH60777::A<T>' |
| 513 |
// CHECK-NEXT: | |-ParmVarDecl 0x{{.+}} <{{.+}}> col:{{.+}} val 'T' |
| 514 |
// CHECK-NEXT: | |-ParmVarDecl 0x{{.+}} <{{.+}}> col:{{.+}} tail 'Ts...' pack |
| 515 |
// CHECK-NEXT: | `-BinaryOperator 0x{{.+}} <{{.+}}> 'bool' '&&' |
| 516 |
// CHECK-NEXT: | |-ParenExpr 0x{{.+}} <{{.+}}> 'bool' |
| 517 |
// CHECK-NEXT: | | `-BinaryOperator 0x{{.+}} <{{.+}}> 'bool' '>' |
| 518 |
// CHECK-NEXT: | | |-UnaryExprOrTypeTraitExpr {{.+}} sizeof 'T' |
| 519 |
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <IntegralCast> |
| 520 |
// CHECK-NEXT: | | `-IntegerLiteral 0x{{.+}} <{{.+}}> 'int' 1 |
| 521 |
// CHECK-NEXT: | `-ParenExpr 0x{{.+}} <{{.+}}> '<dependent type>' |
| 522 |
// CHECK-NEXT: | `-CallExpr 0x{{.+}} <{{.+}}> '<dependent type>' |
| 523 |
// CHECK-NEXT: | `-UnresolvedLookupExpr 0x{{.+}} <col:14, col:24> '<dependent type>' {{.+}} |
| 524 |
// CHECK-NEXT: | `-TemplateArgument type 'Ts...':'type-parameter-0-1...' |
| 525 |
// CHECK-NEXT: | `-PackExpansionType 0x{{.+}} 'Ts...' dependent |
| 526 |
// CHECK-NEXT: | `-TemplateTypeParmType 0x{{.+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack |
| 527 |
// CHECK-NEXT: | `-TemplateTypeParm 0x{{.+}} 'Ts' |
| 528 |
|
| 529 |
template <typename T> |
| 530 |
struct B { |
| 531 |
template <typename... Ts> |
| 532 |
B(T val, Ts... tail) |
| 533 |
requires(True<tail...>()) |
| 534 |
{} |
| 535 |
}; |
| 536 |
|
| 537 |
B b(42, 43); |
| 538 |
// expected-error@-1 {{no viable constructor}} \ |
| 539 |
// expected-note@-6 {{constraints not satisfied}} \ |
| 540 |
// expected-note@-5 {{because substituted constraint expression is ill-formed}} \ |
| 541 |
// expected-note@-6 {{implicit deduction guide declared as 'template <typename T, typename ...Ts> B(T val, Ts ...tail) -> GH60777::B<T> requires (True<tail...>())'}} \ |
| 542 |
// expected-note@-8 {{function template not viable}} \ |
| 543 |
// expected-note@-8 {{implicit deduction guide declared as 'template <typename T> B(GH60777::B<T>) -> GH60777::B<T>'}} |
| 544 |
|
| 545 |
} // namespace GH60777 |
| 546 |
|
| 547 |
// Examples from @hokein. |
| 548 |
namespace GH98592 { |
| 549 |
|
| 550 |
template <class T> concept True = true; |
| 551 |
double arr3[3]; |
| 552 |
|
| 553 |
template <class T> |
| 554 |
struct X { |
| 555 |
const int size; |
| 556 |
template <class U> |
| 557 |
constexpr X(T, U(&)[3]) requires True<T> : size(sizeof(T)) {} |
| 558 |
}; |
| 559 |
|
| 560 |
template <typename T, typename U> |
| 561 |
X(T, U (&)[3]) -> X<U>; |
| 562 |
|
| 563 |
constexpr X x(3, arr3); |
| 564 |
|
| 565 |
// The synthesized deduction guide is more constrained than the explicit one. |
| 566 |
static_assert(x.size == 4); |
| 567 |
|
| 568 |
// CHECK-LABEL: Dumping GH98592::<deduction guide for X>: |
| 569 |
// CHECK-NEXT: FunctionTemplateDecl 0x{{.+}} <{{.+}}> col:13 implicit <deduction guide for X> |
| 570 |
// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} <{{.+}}> col:17 referenced class depth 0 index 0 T |
| 571 |
// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} <{{.+}}> col:19 class depth 0 index 1 U |
| 572 |
// CHECK-NEXT: |-CXXDeductionGuideDecl 0x{{.+}} <{{.+}}> col:13 implicit <deduction guide for X> 'auto (T, U (&)[3]) -> GH98592::X<T>' |
| 573 |
// CHECK-NEXT: | |-ParmVarDecl 0x{{.+}} <col:15> col:16 'T' |
| 574 |
// CHECK-NEXT: | |-ParmVarDecl 0x{{.+}} <col:18, col:24> col:21 'U (&)[3]' |
| 575 |
// CHECK-NEXT: | `-ConceptSpecializationExpr 0x{{.+}} <col:36, col:42> 'bool' Concept 0x{{.+}} 'True' |
| 576 |
// CHECK-NEXT: | |-ImplicitConceptSpecializationDecl 0x{{.+}} <{{.+}}> col:28 |
| 577 |
// CHECK-NEXT: | | `-TemplateArgument type 'T' |
| 578 |
// CHECK-NEXT: | | `-TemplateTypeParmType 0x{{.+}} 'T' dependent depth 0 index 0 |
| 579 |
// CHECK-NEXT: | | `-TemplateTypeParm 0x{{.+}} 'T' |
| 580 |
// CHECK-NEXT: | `-TemplateArgument <{{.+}}> type 'T':'type-parameter-0-0' |
| 581 |
// CHECK-NEXT: | `-TemplateTypeParmType 0x{{.+}} 'T' dependent depth 0 index 0 |
| 582 |
// CHECK-NEXT: | `-TemplateTypeParm 0x{{.+}} 'T' |
| 583 |
// CHECK-NEXT: `-CXXDeductionGuideDecl 0x{{.+}} <col:3, col:63> col:13 implicit used <deduction guide for X> 'auto (int, double (&)[3]) -> GH98592::X<int>' implicit_instantiation |
| 584 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 585 |
// CHECK-NEXT: | `-BuiltinType 0x{{.+}} 'int' |
| 586 |
// CHECK-NEXT: |-TemplateArgument type 'double' |
| 587 |
// CHECK-NEXT: | `-BuiltinType 0x{{.+}} 'double' |
| 588 |
// CHECK-NEXT: |-ParmVarDecl 0x{{.+}} <col:15> col:16 'int' |
| 589 |
// CHECK-NEXT: |-ParmVarDecl 0x{{.+}} <col:18, col:24> col:21 'double (&)[3]' |
| 590 |
// CHECK-NEXT: `-ConceptSpecializationExpr 0x{{.+}} <col:36, col:42> 'bool' Concept 0x{{.+}} 'True' |
| 591 |
// CHECK-NEXT: |-ImplicitConceptSpecializationDecl 0x{{.+}} <{{.+}}> col:28 |
| 592 |
// CHECK-NEXT: | `-TemplateArgument type 'T' |
| 593 |
// CHECK-NEXT: | `-TemplateTypeParmType 0x{{.+}} 'T' dependent depth 0 index 0 |
| 594 |
// CHECK-NEXT: | `-TemplateTypeParm 0x{{.+}} 'T' |
| 595 |
// CHECK-NEXT: `-TemplateArgument <{{.+}}> type 'T':'type-parameter-0-0' |
| 596 |
// CHECK-NEXT: `-TemplateTypeParmType 0x{{.+}} 'T' dependent depth 0 index 0 |
| 597 |
// CHECK-NEXT: `-TemplateTypeParm 0x{{.+}} 'T' |
| 598 |
|
| 599 |
template <class T> requires True<T> struct Y { |
| 600 |
const int size; |
| 601 |
template <class U> |
| 602 |
constexpr Y(T, U(&)[3]) : size(sizeof(T)) {} |
| 603 |
}; |
| 604 |
|
| 605 |
template <typename T, typename U> Y(T, U (&)[3]) -> Y<U>; |
| 606 |
|
| 607 |
constexpr Y y(3, arr3); |
| 608 |
|
| 609 |
// Likewise, the synthesized deduction guide should be preferred |
| 610 |
// according to [over.match.class.deduct]p1. |
| 611 |
static_assert(y.size == 4); |
| 612 |
|
| 613 |
// Dumping GH98592::<deduction guide for Y>: |
| 614 |
// FunctionTemplateDecl 0x{{.+}} <{{.+}}> col:13 implicit <deduction guide for Y> |
| 615 |
// |-TemplateTypeParmDecl 0x{{.+}} <{{.+}}> col:17 referenced class depth 0 index 0 T |
| 616 |
// |-TemplateTypeParmDecl 0x{{.+}} <{{.+}}> col:19 class depth 0 index 1 U |
| 617 |
// |-CXXDeductionGuideDecl 0x{{.+}} <{{.+}}> col:13 implicit <deduction guide for Y> 'auto (T, U (&)[3]) -> Y<T>' |
| 618 |
// | |-ParmVarDecl 0x{{.+}} <col:15> col:16 'T' |
| 619 |
// | |-ParmVarDecl 0x{{.+}} <col:18, col:24> col:21 'U (&)[3]' |
| 620 |
// | `-ConceptSpecializationExpr 0x{{.+}} <{{.+}}> 'bool' Concept 0x{{.+}} 'True' |
| 621 |
// | |-ImplicitConceptSpecializationDecl 0x{{.+}} <{{.+}}> col:28 |
| 622 |
// | | `-TemplateArgument type 'type-parameter-0-0' |
| 623 |
// | | `-TemplateTypeParmType 0x{{.+}} 'type-parameter-0-0' dependent depth 0 index 0 |
| 624 |
// | `-TemplateArgument <{{.+}}> type 'T':'type-parameter-0-0' |
| 625 |
// | `-TemplateTypeParmType 0x{{.+}} 'T' dependent depth 0 index 0 |
| 626 |
// | `-TemplateTypeParm 0x{{.+}} 'T' |
| 627 |
// `-CXXDeductionGuideDecl 0x{{.+}} <{{.+}}> col:13 implicit used <deduction guide for Y> 'auto (int, double (&)[3]) -> GH98592::Y<int>' implicit_instantiation |
| 628 |
// |-TemplateArgument type 'int' |
| 629 |
// | `-BuiltinType 0x{{.+}} 'int' |
| 630 |
// |-TemplateArgument type 'double' |
| 631 |
// | `-BuiltinType 0x{{.+}} 'double' |
| 632 |
// |-ParmVarDecl 0x{{.+}} <col:15> col:16 'int' |
| 633 |
// |-ParmVarDecl 0x{{.+}} <col:18, col:24> col:21 'double (&)[3]' |
| 634 |
// `-ConceptSpecializationExpr 0x{{.+}} <{{.+}}> 'bool' Concept 0x{{.+}} 'True' |
| 635 |
// |-ImplicitConceptSpecializationDecl 0x{{.+}} <{{.+}}> col:28 |
| 636 |
// | `-TemplateArgument type 'type-parameter-0-0' |
| 637 |
// | `-TemplateTypeParmType 0x{{.+}} 'type-parameter-0-0' dependent depth 0 index 0 |
| 638 |
// `-TemplateArgument <{{.+}}> type 'T':'type-parameter-0-0' |
| 639 |
// `-TemplateTypeParmType 0x{{.+}} 'T' dependent depth 0 index 0 |
| 640 |
// `-TemplateTypeParm 0x{{.+}} 'T' |
| 641 |
|
| 642 |
} // namespce GH98592 |
| 643 |
|
| 644 |
namespace GH122134 { |
| 645 |
|
| 646 |
template <class, class> |
| 647 |
concept Constraint = true; |
| 648 |
|
| 649 |
template <class T, int> struct Struct { |
| 650 |
Struct(Constraint<T> auto) {} |
| 651 |
}; |
| 652 |
|
| 653 |
template <int N = 0> using Test = Struct<int, N>; |
| 654 |
|
| 655 |
Test test(42); |
| 656 |
|
| 657 |
// CHECK-LABEL: Dumping GH122134::<deduction guide for Test>: |
| 658 |
// CHECK-NEXT: FunctionTemplateDecl {{.*}} implicit <deduction guide for Test> |
| 659 |
// CHECK-NEXT: |-NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 0 N |
| 660 |
// CHECK-NEXT: | `-TemplateArgument {{.*}} expr '0' |
| 661 |
// CHECK-NEXT: | `-IntegerLiteral {{.*}} 'int' 0 |
| 662 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} Concept {{.*}} 'Constraint' depth 0 index 1 auto:1 |
| 663 |
// CHECK-NEXT: | `-ConceptSpecializationExpr {{.*}} 'bool' Concept {{.*}} 'Constraint' |
| 664 |
// CHECK-NEXT: | |-ImplicitConceptSpecializationDecl {{.*}} |
| 665 |
// CHECK-NEXT: | | |-TemplateArgument type 'auto:1' |
| 666 |
// CHECK-NEXT: | | | `-TemplateTypeParmType {{.*}} 'auto:1' dependent depth 0 index 1 |
| 667 |
// CHECK-NEXT: | | | `-TemplateTypeParm {{.*}} 'auto:1' |
| 668 |
// CHECK-NEXT: | | `-TemplateArgument type 'int' |
| 669 |
// CHECK-NEXT: | | `-BuiltinType {{.*}} 'int' |
| 670 |
// CHECK-NEXT: | |-TemplateArgument {{.*}} type 'auto:1':'type-parameter-0-1' |
| 671 |
// CHECK-NEXT: | | `-TemplateTypeParmType {{.*}} 'auto:1' dependent depth 0 index 1 |
| 672 |
// CHECK-NEXT: | | `-TemplateTypeParm {{.*}} 'auto:1' |
| 673 |
// CHECK-NEXT: | `-TemplateArgument {{.*}} type 'int' |
| 674 |
// CHECK-NEXT: | `-BuiltinType {{.*}} 'int' |
| 675 |
// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible |
| 676 |
// CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.*}} 'GH122134::Test' dependent |
| 677 |
// CHECK-NEXT: | | `-name: 'GH122134::Test' |
| 678 |
// CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.*}} Test |
| 679 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.*}} 'GH122134::Struct<int, N>' dependent |
| 680 |
// CHECK-NEXT: | |-name: 'GH122134::Struct' |
| 681 |
// CHECK-NEXT: | | `-ClassTemplateDecl {{.*}} Struct |
| 682 |
// CHECK-NEXT: | |-TemplateArgument type 'int' |
| 683 |
// CHECK-NEXT: | | `-SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 T |
| 684 |
// CHECK-NEXT: | | |-FunctionTemplate {{.*}} '<deduction guide for Struct>' |
| 685 |
// CHECK-NEXT: | | `-BuiltinType {{.*}} 'int' |
| 686 |
// CHECK-NEXT: | `-TemplateArgument expr 'N' |
| 687 |
// CHECK-NEXT: | `-SubstNonTypeTemplateParmExpr {{.*}} 'int' |
| 688 |
// CHECK-NEXT: | |-NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 1 |
| 689 |
// CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'N' 'int' |
| 690 |
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Test> 'auto (auto:1) -> GH122134::Struct<int, N>' |
| 691 |
// CHECK-NEXT: | `-ParmVarDecl {{.*}} 'auto:1' |
| 692 |
|
| 693 |
} // namespace GH122134 |
| 694 |
|
| 695 |
namespace GH128691 { |
| 696 |
|
| 697 |
template <typename = void> |
| 698 |
class NewDeleteAllocator; |
| 699 |
|
| 700 |
template <> |
| 701 |
struct NewDeleteAllocator<> { |
| 702 |
template <typename T> |
| 703 |
NewDeleteAllocator(T); // expected-note {{candidate template ignored}} \ |
| 704 |
// expected-note {{implicit deduction guide declared as}} |
| 705 |
}; |
| 706 |
|
| 707 |
template <typename> |
| 708 |
struct NewDeleteAllocator : NewDeleteAllocator<> { // expected-note {{candidate template ignored}} \ |
| 709 |
// expected-note {{implicit deduction guide declared as}} |
| 710 |
using NewDeleteAllocator<>::NewDeleteAllocator; |
| 711 |
}; |
| 712 |
|
| 713 |
void test() { NewDeleteAllocator abc(42); } // expected-error {{no viable constructor or deduction guide}} |
| 714 |
|
| 715 |
// CHECK-LABEL: Dumping GH128691::<deduction guide for NewDeleteAllocator>: |
| 716 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} <deduction guide for NewDeleteAllocator> |
| 717 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 0 |
| 718 |
// CHECK-NEXT: | `-TemplateArgument type 'void' |
| 719 |
// CHECK-NEXT: | |-inherited from TemplateTypeParm {{.+}} depth 0 index 0 |
| 720 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'void' |
| 721 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 1 T |
| 722 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <deduction guide for NewDeleteAllocator> 'auto (T) -> GH128691::NewDeleteAllocator<type-parameter-0-0>' |
| 723 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} 'T' |
| 724 |
|
| 725 |
} // namespace GH128691 |
| 726 |
|
| 727 |
namespace GH132616_DeductionGuide { |
| 728 |
|
| 729 |
template <class T> struct A { |
| 730 |
template <class U> |
| 731 |
A(U); |
| 732 |
}; |
| 733 |
|
| 734 |
template <typename> |
| 735 |
struct B : A<int> { |
| 736 |
using A::A; |
| 737 |
}; |
| 738 |
|
| 739 |
template <class T> |
| 740 |
B(T) -> B<T>; |
| 741 |
|
| 742 |
B b(24); |
| 743 |
|
| 744 |
// CHECK-LABEL: Dumping GH132616_DeductionGuide::<deduction guide for B>: |
| 745 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for B> |
| 746 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 0 |
| 747 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U |
| 748 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for B> 'auto (U) -> GH132616_DeductionGuide::B<type-parameter-0-0>' |
| 749 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} 'U' |
| 750 |
|
| 751 |
struct C { |
| 752 |
template <class U> |
| 753 |
C(U); |
| 754 |
}; |
| 755 |
|
| 756 |
template <typename> |
| 757 |
struct D : C { |
| 758 |
using C::C; |
| 759 |
}; |
| 760 |
|
| 761 |
template <class T> |
| 762 |
D(T) -> D<T>; |
| 763 |
|
| 764 |
D d(24); |
| 765 |
|
| 766 |
// CHECK-LABEL: Dumping GH132616_DeductionGuide::<deduction guide for D>: |
| 767 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for D> |
| 768 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 0 |
| 769 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U |
| 770 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for D> 'auto (U) -> GH132616_DeductionGuide::D<type-parameter-0-0>' |
| 771 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} 'U' |
| 772 |
|
| 773 |
} // namespace GH132616_DeductionGuide |
| 774 |
|
| 775 |
namespace GH133132 { |
| 776 |
|
| 777 |
template <class _Ty> |
| 778 |
struct A {}; |
| 779 |
|
| 780 |
template <class T = int, class U = T> |
| 781 |
using AA = A<U>; |
| 782 |
|
| 783 |
AA a{}; |
| 784 |
|
| 785 |
// CHECK-LABEL: Dumping GH133132::<deduction guide for AA>: |
| 786 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for AA> |
| 787 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T |
| 788 |
// CHECK-NEXT: | `-TemplateArgument type 'int' |
| 789 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 790 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U |
| 791 |
// CHECK-NEXT: | `-TemplateArgument type 'T':'type-parameter-0-0' |
| 792 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0 |
| 793 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T' |
| 794 |
// CHECK-NEXT: |-TypeTraitExpr {{.+}} 'bool' __is_deducible |
| 795 |
// CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.+}} 'GH133132::AA' dependent |
| 796 |
// CHECK-NEXT: | | `-name: 'GH133132::AA' |
| 797 |
// CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.+}} AA |
| 798 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.+}} 'GH133132::A<U>' dependent |
| 799 |
// CHECK-NEXT: | |-name: 'GH133132::A' |
| 800 |
// CHECK-NEXT: | | `-ClassTemplateDecl {{.+}} A |
| 801 |
// CHECK-NEXT: | `-TemplateArgument type 'U':'type-parameter-0-1' |
| 802 |
// CHECK-NEXT: | `-SubstTemplateTypeParmType {{.+}} 'U' sugar dependent class depth 0 index 0 _Ty |
| 803 |
// CHECK-NEXT: | |-FunctionTemplate {{.+}} '<deduction guide for A>' |
| 804 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 805 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'U' |
| 806 |
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for AA> 'auto () -> GH133132::A<U>' |
| 807 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit used <deduction guide for AA> 'auto () -> GH133132::A<int>' implicit_instantiation |
| 808 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 809 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 810 |
// CHECK-NEXT: `-TemplateArgument type 'int' |
| 811 |
// CHECK-NEXT: `-BuiltinType {{.+}} 'int' |
| 812 |
|
| 813 |
template <template <class> class _X> |
| 814 |
struct B {}; |
| 815 |
|
| 816 |
template <template <class> class _X = A, template <class> class _Y = _X> |
| 817 |
using BB = B<_Y>; |
| 818 |
|
| 819 |
BB b{}; |
| 820 |
|
| 821 |
// CHECK-LABEL: Dumping GH133132::<deduction guide for BB>: |
| 822 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for BB> |
| 823 |
// CHECK-NEXT: |-TemplateTemplateParmDecl {{.+}} depth 0 index 0 _X |
| 824 |
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 |
| 825 |
// CHECK-NEXT: | `-TemplateArgument {{.+}} template 'A':'GH133132::A' qualified |
| 826 |
// CHECK-NEXT: | `-ClassTemplateDecl {{.+}} A |
| 827 |
// CHECK-NEXT: |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 _Y |
| 828 |
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 |
| 829 |
// CHECK-NEXT: | `-TemplateArgument {{.+}} template '_X':'template-parameter-0-0' |
| 830 |
// CHECK-NEXT: | `-TemplateTemplateParmDecl {{.+}} depth 0 index 0 _X |
| 831 |
// CHECK-NEXT: |-TypeTraitExpr {{.+}} 'bool' __is_deducible |
| 832 |
// CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.+}} 'GH133132::BB' dependent |
| 833 |
// CHECK-NEXT: | | `-name: 'GH133132::BB' |
| 834 |
// CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.+}} BB |
| 835 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.+}} 'GH133132::B<_Y>' dependent |
| 836 |
// CHECK-NEXT: | |-name: 'GH133132::B' |
| 837 |
// CHECK-NEXT: | | `-ClassTemplateDecl {{.+}} B |
| 838 |
// CHECK-NEXT: | `-TemplateArgument template '_Y':'template-parameter-0-1' subst index 0 |
| 839 |
// CHECK-NEXT: | |-parameter: TemplateTemplateParmDecl {{.+}} depth 0 index 0 _X |
| 840 |
// CHECK-NEXT: | |-associated FunctionTemplate {{.+}} '<deduction guide for B>' |
| 841 |
// CHECK-NEXT: | `-replacement: '_Y':'template-parameter-0-1' |
| 842 |
// CHECK-NEXT: | `-TemplateTemplateParmDecl {{.+}} depth 0 index 1 _Y |
| 843 |
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for BB> 'auto () -> GH133132::B<_Y>' |
| 844 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit used <deduction guide for BB> 'auto () -> GH133132::B<GH133132::A>' implicit_instantiation |
| 845 |
// CHECK-NEXT: |-TemplateArgument template 'GH133132::A' |
| 846 |
// CHECK-NEXT: | `-ClassTemplateDecl {{.+}} A |
| 847 |
// CHECK-NEXT: `-TemplateArgument template 'GH133132::A' |
| 848 |
// CHECK-NEXT: `-ClassTemplateDecl {{.+}} A |
| 849 |
|
| 850 |
template <int N = 42, class U = A<decltype(N)>> |
| 851 |
using CC = A<U>; |
| 852 |
|
| 853 |
CC c{}; |
| 854 |
|
| 855 |
// CHECK-LABEL: Dumping GH133132::<deduction guide for CC>: |
| 856 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for CC> |
| 857 |
// CHECK-NEXT: |-NonTypeTemplateParmDecl {{.+}} 'int' depth 0 index 0 N |
| 858 |
// CHECK-NEXT: | `-TemplateArgument {{.+}} expr '42' |
| 859 |
// CHECK-NEXT: | `-IntegerLiteral {{.+}} 'int' 42 |
| 860 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U |
| 861 |
// CHECK-NEXT: | `-TemplateArgument type 'A<decltype(N)>' |
| 862 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.+}} 'A<decltype(N)>' dependent |
| 863 |
// CHECK-NEXT: | |-name: 'A':'GH133132::A' qualified |
| 864 |
// CHECK-NEXT: | | `-ClassTemplateDecl {{.+}} A |
| 865 |
// CHECK-NEXT: | `-TemplateArgument type 'decltype(N)' |
| 866 |
// CHECK-NEXT: | `-DecltypeType {{.+}} 'decltype(N)' dependent |
| 867 |
// CHECK-NEXT: | `-DeclRefExpr {{.+}} 'int' NonTypeTemplateParm {{.+}} 'N' 'int' |
| 868 |
// CHECK-NEXT: |-TypeTraitExpr {{.+}} 'bool' __is_deducible |
| 869 |
// CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.+}} 'GH133132::CC' dependent |
| 870 |
// CHECK-NEXT: | | `-name: 'GH133132::CC' |
| 871 |
// CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.+}} CC |
| 872 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.+}} 'GH133132::A<U>' dependent |
| 873 |
// CHECK-NEXT: | |-name: 'GH133132::A' |
| 874 |
// CHECK-NEXT: | | `-ClassTemplateDecl {{.+}} A |
| 875 |
// CHECK-NEXT: | `-TemplateArgument type 'U':'type-parameter-0-1' |
| 876 |
// CHECK-NEXT: | `-SubstTemplateTypeParmType {{.+}} 'U' sugar dependent class depth 0 index 0 _Ty |
| 877 |
// CHECK-NEXT: | |-FunctionTemplate {{.+}} '<deduction guide for A>' |
| 878 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1 |
| 879 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'U' |
| 880 |
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for CC> 'auto () -> GH133132::A<U>' |
| 881 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit used <deduction guide for CC> 'auto () -> GH133132::A<GH133132::A<int>>' implicit_instantiation |
| 882 |
// CHECK-NEXT: |-TemplateArgument integral '42' |
| 883 |
// CHECK-NEXT: `-TemplateArgument type 'GH133132::A<int>' |
| 884 |
// CHECK-NEXT: `-RecordType {{.+}} 'GH133132::A<int>' |
| 885 |
// CHECK-NEXT: `-ClassTemplateSpecialization {{.+}} 'A' |
| 886 |
|
| 887 |
} |
| 888 |
|
| 889 |
namespace GH67173 { |
| 890 |
|
| 891 |
template <class T> struct Vec2d { |
| 892 |
struct { |
| 893 |
T x; |
| 894 |
T y; |
| 895 |
}; |
| 896 |
}; |
| 897 |
|
| 898 |
void f() { |
| 899 |
Vec2d v{.x = 1, .y = 2}; |
| 900 |
} |
| 901 |
|
| 902 |
// CHECK-LABEL: Dumping GH67173::<deduction guide for Vec2d>: |
| 903 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for Vec2d> |
| 904 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} referenced class depth 0 index 0 T |
| 905 |
// CHECK: |-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for Vec2d> 'auto (T, T) -> GH67173::Vec2d<T>' aggregate |
| 906 |
// CHECK-NEXT: | |-ParmVarDecl {{.+}} col:27 'T' |
| 907 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} col:27 'T' |
| 908 |
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} implicit used <deduction guide for Vec2d> 'auto (int, int) -> GH67173::Vec2d<int>' implicit_instantiation instantiated_from 0x{{.+}} aggregate |
| 909 |
// CHECK-NEXT: |-TemplateArgument type 'int' |
| 910 |
// CHECK-NEXT: | `-BuiltinType {{.+}} 'int' |
| 911 |
// CHECK-NEXT: |-ParmVarDecl {{.+}} 'int' |
| 912 |
// CHECK-NEXT: `-ParmVarDecl {{.+}} 'int' |
| 913 |
|
| 914 |
} |
| 915 |
|
| 916 |
namespace GH141425 { |
| 917 |
|
| 918 |
template<class... Lambda> |
| 919 |
struct Container |
| 920 |
{ |
| 921 |
Container(Lambda...) {} |
| 922 |
}; |
| 923 |
|
| 924 |
template<class... T> |
| 925 |
using Alias = Container<T...>; |
| 926 |
|
| 927 |
template<class = void> |
| 928 |
struct Invocable { |
| 929 |
using T = decltype([]() { |
| 930 |
(void)Alias([]() -> void {}); |
| 931 |
}()); |
| 932 |
}; |
| 933 |
|
| 934 |
struct Type { |
| 935 |
using T = bool; |
| 936 |
}; |
| 937 |
|
| 938 |
template<class...> |
| 939 |
struct ExpandType { |
| 940 |
using T = bool; |
| 941 |
}; |
| 942 |
|
| 943 |
template<class... X> |
| 944 |
using Expand = ExpandType<typename X::T...>; |
| 945 |
|
| 946 |
Expand<Type, Invocable<>> _{}; |
| 947 |
|
| 948 |
// CHECK-LABEL: Dumping GH141425::<deduction guide for Alias>: |
| 949 |
// CHECK-NEXT: FunctionTemplateDecl {{.+}} implicit <deduction guide for Alias> |
| 950 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 ... T |
| 951 |
// CHECK-NEXT: |-TypeTraitExpr {{.+}} 'bool' __is_deducible |
| 952 |
// CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.+}} 'GH141425::Alias' dependent |
| 953 |
// CHECK-NEXT: | | `-name: 'GH141425::Alias' |
| 954 |
// CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.+}} Alias |
| 955 |
// CHECK-NEXT: | `-TemplateSpecializationType {{.+}} 'GH141425::Container<T...>' dependent |
| 956 |
// CHECK-NEXT: | |-name: 'GH141425::Container' |
| 957 |
// CHECK-NEXT: | | `-ClassTemplateDecl {{.+}} Container |
| 958 |
// CHECK-NEXT: | `-TemplateArgument type 'T...':'type-parameter-0-0...' |
| 959 |
// CHECK-NEXT: | `-PackExpansionType {{.+}} 'T...' dependent |
| 960 |
// CHECK-NEXT: | `-SubstTemplateTypeParmType {{.+}} 'T' sugar dependent contains_unexpanded_pack class depth 0 index 0 ... Lambda pack_index 0 |
| 961 |
// CHECK-NEXT: | |-FunctionTemplate {{.+}} '<deduction guide for Container>' |
| 962 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack |
| 963 |
// CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T' |
| 964 |
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.+}} implicit <deduction guide for Alias> 'auto (T...) -> GH141425::Container<T...>' |
| 965 |
// CHECK-NEXT: | `-ParmVarDecl {{.+}} 'T...' pack |
| 966 |
|
| 967 |
} |
| 968 |
|
| 969 |
namespace GH134613 { |
| 970 |
template <typename R> struct Foo { |
| 971 |
using value_type = R; |
| 972 |
|
| 973 |
Foo() = default; |
| 974 |
Foo(Foo<Foo<R>> &&rhs) {} |
| 975 |
}; |
| 976 |
|
| 977 |
void main() { |
| 978 |
auto r1 = Foo(Foo<Foo<int>>{}); |
| 979 |
|
| 980 |
static_assert(__is_same(decltype(r1)::value_type, int)); |
| 981 |
} |
| 982 |
|
| 983 |
} |