| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump -ast-dump-decl-types -ast-dump-filter Foo %s | FileCheck -strict-whitespace %s |
| 2 |
|
| 3 |
// Test with serialization: |
| 4 |
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s |
| 5 |
// RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \ |
| 6 |
// RUN: -ast-dump-all -ast-dump-decl-types -ast-dump-filter Foo /dev/null \ |
| 7 |
// RUN: | FileCheck --strict-whitespace %s |
| 8 |
|
| 9 |
template <typename T> |
| 10 |
concept unary_concept = true; |
| 11 |
|
| 12 |
template <typename T, typename U> |
| 13 |
concept binary_concept = true; |
| 14 |
|
| 15 |
template <typename... Ts> |
| 16 |
concept variadic_concept = true; |
| 17 |
|
| 18 |
template <typename T> |
| 19 |
struct Foo { |
| 20 |
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept' |
| 21 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:13, col:31> 'bool' Concept {{.*}} 'binary_concept' |
| 22 |
// CHECK-NEXT: |-ImplicitConceptSpecializationDecl {{.*}} <line:13:9> col:9 |
| 23 |
// CHECK-NEXT: | |-TemplateArgument type 'R' |
| 24 |
// CHECK-NEXT: | | `-TemplateTypeParmType {{.*}} 'R' dependent {{.*}}depth 1 index 0 |
| 25 |
// CHECK-NEXT: | | `-TemplateTypeParm {{.*}} 'R' |
| 26 |
// CHECK-NEXT: | `-TemplateArgument type 'int' |
| 27 |
// CHECK-NEXT: | `-BuiltinType {{.*}} 'int' |
| 28 |
// CHECK-NEXT: |-TemplateArgument {{.*}} type 'R' |
| 29 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.*}} 'R' |
| 30 |
// CHECK-NEXT: | `-TemplateTypeParm {{.*}} 'R' |
| 31 |
// CHECK-NEXT: `-TemplateArgument {{.*}} type 'int' |
| 32 |
// CHECK-NEXT: `-BuiltinType {{.*}} 'int' |
| 33 |
template <binary_concept<int> R> |
| 34 |
Foo(R); |
| 35 |
|
| 36 |
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'unary_concept' |
| 37 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:13> 'bool' |
| 38 |
// CHECK-NEXT: |-ImplicitConceptSpecializationDecl {{.*}} <line:10:9> col:9 |
| 39 |
// CHECK-NEXT: | `-TemplateArgument type 'R' |
| 40 |
// CHECK-NEXT: | `-TemplateTypeParmType {{.*}} 'R' dependent {{.*}}depth 1 index 0 |
| 41 |
// CHECK-NEXT: | `-TemplateTypeParm {{.*}} 'R' |
| 42 |
template <unary_concept R> |
| 43 |
Foo(R); |
| 44 |
|
| 45 |
// CHECK: FunctionTemplateDecl {{.*}} <line:[[@LINE+1]]:3, line:[[@LINE+2]]:39> {{.*}} Foo<T> |
| 46 |
template <typename R> |
| 47 |
Foo(R, int) requires unary_concept<R>; |
| 48 |
|
| 49 |
// CHECK: FunctionTemplateDecl {{.*}} <line:[[@LINE+1]]:3, line:[[@LINE+3]]:3> {{.*}} Foo<T> |
| 50 |
template <typename R> |
| 51 |
Foo(R, char) requires unary_concept<R> { |
| 52 |
} |
| 53 |
|
| 54 |
// CHECK: CXXFoldExpr {{.*}} <col:13, col:29> |
| 55 |
template <variadic_concept... Ts> |
| 56 |
Foo(); |
| 57 |
|
| 58 |
// CHECK: CXXFoldExpr {{.*}} <col:13, col:34> |
| 59 |
template <variadic_concept<int>... Ts> |
| 60 |
Foo(); |
| 61 |
|
| 62 |
// CHECK:InjectedClassNameType |
| 63 |
// CHECK-NEXT: CXXRecord {{.*}} 'Foo' |
| 64 |
}; |
| 65 |
|
| 66 |
namespace GH82628 { |
| 67 |
namespace ns { |
| 68 |
|
| 69 |
template <typename T> |
| 70 |
concept C = true; |
| 71 |
|
| 72 |
} // namespace ns |
| 73 |
|
| 74 |
using ns::C; |
| 75 |
|
| 76 |
// CHECK: ConceptDecl {{.*}} Foo |
| 77 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T |
| 78 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C' |
| 79 |
template <typename T> |
| 80 |
concept Foo = C<T>; |
| 81 |
|
| 82 |
// CHECK: TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C') |
| 83 |
// CHECK: QualType |
| 84 |
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool' |
| 85 |
template <C T> |
| 86 |
constexpr bool FooVar = false; |
| 87 |
|
| 88 |
// CHECK: ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C' |
| 89 |
// CHECK: QualType |
| 90 |
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool' |
| 91 |
template <typename T> requires C<T> |
| 92 |
constexpr bool FooVar2 = true; |
| 93 |
|
| 94 |
// CHECK: SimpleRequirement |
| 95 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C' |
| 96 |
// CHECK: QualType |
| 97 |
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool' |
| 98 |
template <typename T> requires requires (T) { C<T>; } |
| 99 |
constexpr bool FooVar3 = true; |
| 100 |
|
| 101 |
// CHECK: NonTypeTemplateParmDecl |
| 102 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C' |
| 103 |
// CHECK: QualType |
| 104 |
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool' |
| 105 |
template <C auto T> |
| 106 |
constexpr bool FooVar4 = bool(T()); |
| 107 |
|
| 108 |
// CHECK: FunctionTemplateDecl |
| 109 |
// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C') depth 0 index 0 ... T |
| 110 |
// CHECK: NonTypeTemplateParmDecl {{.*}} depth 0 index 1 U |
| 111 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C' |
| 112 |
// CHECK: |-TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C') depth 0 index 2 V:auto |
| 113 |
// CHECK: FunctionProtoType |
| 114 |
// CHECK: `-Concept {{.*}} 'C' |
| 115 |
// CHECK: `-TemplateTypeParm {{.*}} 'V:auto' |
| 116 |
template <C... T, C auto U> |
| 117 |
auto FooFunc(C auto V) -> C decltype(auto) { |
| 118 |
// FIXME: TypeLocs inside of the function body cannot be dumped via -ast-dump for now. |
| 119 |
// See clang-tools-extra/clangd/unittests/SelectionTests.cpp:SelectionTest.UsingConcepts for their checkings. |
| 120 |
C auto W = V; |
| 121 |
return W; |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
namespace constraint_auto_params { |
| 127 |
|
| 128 |
template <class T, class K> |
| 129 |
concept C = true; |
| 130 |
|
| 131 |
template<class T> |
| 132 |
void g(C<T> auto Foo) {} |
| 133 |
|
| 134 |
// CHECK: TemplateTypeParmDecl {{.*}} depth 0 index 1 Foo:auto |
| 135 |
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:8, col:11> |
| 136 |
|
| 137 |
} |