brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.2 KiB · 9a3adbc Raw
205 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump %s | FileCheck -strict-whitespace %s2 3template <typename, typename>4constexpr bool Concept = true;5template<typename T> // depth 06struct Out {7  template<typename U> // depth 18  struct Inner {9    U t;10  };11 12  template<typename V> // depth113  requires Concept<T, V>14  Inner(V) -> Inner<V>;15};16 17template <typename X>18struct Out2 {19  template<typename Y> // depth120  using AInner = Out<int>::Inner<Y>;21};22Out2<double>::AInner t(1.0);23 24// Verify that the require-clause of alias deduction guide is transformed correctly:25//   - Occurrence T should be replaced with `int`;26//   - Occurrence V should be replaced with the Y with depth 127//   - Depth of occurrence Y in the __is_deducible constraint should be 128//29// CHECK:      |   `-FunctionTemplateDecl {{.*}} <deduction guide for AInner>30// CHECK-NEXT: |     |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 Y31// CHECK-NEXT: |     |-BinaryOperator {{.*}} '<dependent type>' '&&'32// CHECK-NEXT: |     | |-UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'Concept'33// CHECK-NEXT: |     | | |-TemplateArgument type 'int'34// CHECK-NEXT: |     | | | `-BuiltinType {{.*}} 'int'35// CHECK-NEXT: |     | | `-TemplateArgument type 'Y':'type-parameter-1-0'36// CHECK-NEXT: |     | |   `-TemplateTypeParmType {{.*}} 'Y' dependent depth 1 index 037// CHECK-NEXT: |     | |     `-TemplateTypeParm {{.*}} 'Y'38// CHECK-NEXT: |     | `-TypeTraitExpr {{.*}} 'bool' __is_deducible39// CHECK-NEXT: |     |   |-DeducedTemplateSpecializationType {{.*}} 'Out2<double>::AInner' dependent40// CHECK-NEXT: |     |   | `-name: 'Out2<double>::AInner'41// CHECK-NEXT: |     |   |   `-TypeAliasTemplateDecl {{.+}} AInner{{$}}42// CHECK-NEXT: |     |   `-TemplateSpecializationType {{.*}} 'Inner<Y>' dependent43// CHECK-NEXT: |     |     |-name: 'Inner':'Out<int>::Inner' qualified44// CHECK-NEXT: |     |     | `-ClassTemplateDecl {{.+}} Inner{{$}}45// CHECK-NEXT: |     |     `-TemplateArgument type 'Y'46// CHECK-NEXT: |     |       `-SubstTemplateTypeParmType {{.*}} 'Y'47// CHECK-NEXT: |     |         |-FunctionTemplate {{.*}} '<deduction guide for Inner>'48// CHECK-NEXT: |     |         `-TemplateTypeParmType {{.*}} 'Y' dependent depth 1 index 049// CHECK-NEXT: |     |           `-TemplateTypeParm {{.*}} 'Y'50// CHECK-NEXT: |     |-CXXDeductionGuideDecl {{.*}} <deduction guide for AInner> 'auto (Y) -> Inner<Y>'51// CHECK-NEXT: |     | `-ParmVarDecl {{.*}} 'Y'52// CHECK-NEXT: |     `-CXXDeductionGuideDecl {{.*}} used <deduction guide for AInner> 'auto (double) -> Inner<double>' implicit_instantiation53// CHECK-NEXT: |       |-TemplateArgument type 'double'54// CHECK-NEXT: |       | `-BuiltinType {{.*}} 'double'55// CHECK-NEXT: |       `-ParmVarDecl {{.*}} 'double'56 57// GH9259658template <typename T0>59struct Out3 {60  template<class T1, typename T2>61  struct Foo {62    // Deduction guide:63    //   template <typename T1, typename T2, typename V>64    //   Foo(V, T1) -> Foo<T1, T2>;65    template<class V> requires Concept<T0, V> // V in require clause of Foo deduction guide: depth 1, index: 266    Foo(V, T1);67  };68};69template<class T3>70using AFoo3 = Out3<int>::Foo<T3, T3>;71AFoo3 afoo3{0, 1};72// Verify occurrence V in the require-clause is transformed (depth: 1 => 0, index: 2 => 1) correctly.73 74// CHECK:      FunctionTemplateDecl {{.*}} implicit <deduction guide for AFoo3>75// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T376// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 1 V77// CHECK-NEXT: |-BinaryOperator {{.*}} '<dependent type>' '&&'78// CHECK-NEXT: | |-UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'Concept'79// CHECK-NEXT: | | |-TemplateArgument type 'int'80// CHECK-NEXT: | | | `-BuiltinType {{.*}} 'int'81// CHECK-NEXT: | | `-TemplateArgument type 'V'82// CHECK-NEXT: | |   `-TemplateTypeParmType {{.*}} 'V' dependent depth 0 index 183 84template <typename... T1>85struct Foo {86  Foo(T1...);87};88 89template <typename...T2>90using AFoo = Foo<T2...>;91AFoo a(1, 2);92// CHECK:      |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for AFoo> 'auto (T2...) -> Foo<T2...>'93// CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'T2...' pack94// CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for AFoo> 'auto (int, int) -> Foo<int, int>' implicit_instantiation95 96template <typename T>97using BFoo = Foo<T, T>;98BFoo b2(1.0, 2.0);99// CHECK:      |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for BFoo> 'auto (T, T) -> Foo<T, T>'100// CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'T'101// CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'T'102// CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for BFoo> 'auto (double, double) -> Foo<double, double>' implicit_instantiation103 104namespace GH90209 {105// Case 1: type template parameter106template <class Ts>107struct List1 {108  List1(int);109};110 111template <class T1>112struct TemplatedClass1 {113  TemplatedClass1(T1);114};115 116template <class T1>117TemplatedClass1(T1) -> TemplatedClass1<List1<T1>>;118 119template <class T2>120using ATemplatedClass1 = TemplatedClass1<List1<T2>>;121 122ATemplatedClass1 test1(1);123// Verify that we have a correct template parameter list for the deduction guide.124//125// CHECK:      FunctionTemplateDecl {{.*}} <deduction guide for ATemplatedClass1>126// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2127// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible128 129// Case 2: template template parameter130template<typename K> struct Foo{};131 132template <template<typename> typename Ts>133struct List2 {134  List2(int);135};136 137template <typename T1>138struct TemplatedClass2 {139  TemplatedClass2(T1);140};141 142template <template<typename> typename T1>143TemplatedClass2(T1<int>) -> TemplatedClass2<List2<T1>>;144 145template <template<typename> typename T2>146using ATemplatedClass2 = TemplatedClass2<List2<T2>>;147 148List2<Foo> list(1);149ATemplatedClass2 test2(list);150// Verify that we have a correct template parameter list for the deduction guide.151//152// CHECK:      FunctionTemplateDecl {{.*}} <deduction guide for ATemplatedClass2>153// CHECK-NEXT: |-TemplateTemplateParmDecl {{.*}} depth 0 index 0 T2154// CHECK-NEXT: | `-TemplateTypeParmDecl {{.*}} typename depth 0 index 0155// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible156 157} // namespace GH90209158 159namespace GH124715 {160 161template <class T, class... Args>162concept invocable = true;163 164template <class T, class... Args> struct Struct {165  template <class U>166    requires invocable<U, Args...>167  Struct(U, Args...) {}168};169 170template <class...> struct Packs {};171 172template <class Lambda, class... Args>173Struct(Lambda lambda, Args... args) -> Struct<Lambda, Args...>;174 175template <class T, class... Ts> using Alias = Struct<T, Packs<Ts...>>;176 177void foo() {178  Alias([](int) {}, Packs<int>());179}180 181// CHECK:      |-FunctionTemplateDecl {{.*}} implicit <deduction guide for Alias>182// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T183// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 1 ... Ts184// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 2 U185// CHECK-NEXT: | |-BinaryOperator {{.*}} 'bool' '&&'186// CHECK-NEXT: | | |-ConceptSpecializationExpr {{.*}} 'bool' Concept {{.*}} 'invocable'187// CHECK-NEXT: | | | |-ImplicitConceptSpecializationDecl {{.*}}188// CHECK-NEXT: | | | | |-TemplateArgument type 'U'189// CHECK-NEXT: | | | | | `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2190// CHECK-NEXT: | | | | |   `-TemplateTypeParm {{.*}} 'U'191// CHECK-NEXT: | | | | `-TemplateArgument pack '<Packs<Ts...>>'192// CHECK-NEXT: | | | |   `-TemplateArgument type 'Packs<Ts...>'193// CHECK-NEXT: | | | |     `-TemplateSpecializationType {{.*}} 'Packs<Ts...>' dependent194// CHECK-NEXT: | | | |       |-name: 'Packs':'GH124715::Packs' qualified195// CHECK-NEXT: | | | |       | `-ClassTemplateDecl {{.*}} Packs196// CHECK-NEXT: | | | |       `-TemplateArgument type 'Ts...'197// CHECK-NEXT: | | | |         `-PackExpansionType {{.*}} 'Ts...' dependent198// CHECK-NEXT: | | | |           `-TemplateTypeParmType {{.*}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack199// CHECK-NEXT: | | | |             `-TemplateTypeParm {{.*}} 'Ts'200// CHECK-NEXT: | | | |-TemplateArgument {{.*}} type 'U':'type-parameter-0-2'201// CHECK-NEXT: | | | | `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2202// CHECK-NEXT: | | | |   `-TemplateTypeParm {{.*}} 'U'203 204} // namespace GH124715205