1 // Test without serialization:
2 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
3 // RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
5 // Test with serialization:
6 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown -include-pch %t -ast-dump-all /dev/null \
8 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9 // RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
11 template <typename Ty
>
12 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> col:6 a
13 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty
16 template <typename
... Ty
>
17 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:13> col:6 b
18 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:23> col:23 referenced typename depth 0 index 0 ... Ty
21 template <typename Ty
, typename Uy
>
22 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:14> col:6 c
23 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty
24 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <col:24, col:33> col:33 referenced typename depth 0 index 1 Uy
28 void c
<float, int>(float, int);
29 // CHECK: FunctionDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <line:[[@LINE-2]]:1, line:[[@LINE-1]]:30> col:6 c 'void (float, int)'
30 // CHECK: TemplateArgument type 'float'
31 // CHECK: TemplateArgument type 'int'
33 template <typename Ty
, template<typename
> typename Uy
>
34 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+4]]:18> col:6 d
35 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty
36 // CHECK-NEXT: TemplateTemplateParmDecl 0x{{[^ ]*}} <col:24, col:52> col:52 depth 0 index 1 Uy
37 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <col:33> col:41 typename depth 1 index 0
41 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:10> col:6 e
42 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:17> col:17 referenced class depth 0 index 0 Ty
46 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:17> col:6 f
47 // CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:15> col:15 referenced 'int' depth 0 index 0 N
50 template <typename Ty
= int>
51 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:10> col:6 g
52 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:25> col:20 referenced typename depth 0 index 0 Ty
53 // CHECK-NEXT: TemplateArgument type 'int'
56 template <typename
= void>
57 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:8> col:6 h
58 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:22> col:20 typename depth 0 index 0
59 // CHECK-NEXT: TemplateArgument type 'void'
62 template <typename Ty
>
63 // CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:11> col:8 R
64 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 0 index 0 Ty
65 // CHECK: ClassTemplateSpecialization 0x{{[^ ]*}} 'R'
69 // CHECK: ClassTemplateSpecializationDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:16> col:8 struct R definition
70 // CHECK: TemplateArgument type 'int'
73 template <typename Ty
, class Uy
>
74 // CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:11> col:8 S
75 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 0 index 0 Ty
76 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <col:24, col:30> col:30 class depth 0 index 1 Uy
79 template <typename Ty
>
80 // CHECK: ClassTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+4]]:20> col:8 struct S definition
81 // CHECK: TemplateArgument type 'type-parameter-0-0'
82 // CHECK: TemplateArgument type 'int'
83 // CHECK: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-4]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty
87 // CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:11> col:8 T
88 // CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11> col:15 'auto' depth 0 index 0
91 template <decltype(auto)>
92 // CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:11> col:8 U
93 // CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:24> col:25 'decltype(auto)' depth 0 index 0
96 template <typename Ty
>
97 // CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+7]]:1> line:[[@LINE+2]]:8 V
98 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 0 index 0 Ty
100 template <typename Uy
>
101 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, line:[[@LINE+2]]:10> col:8 f
102 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:13, col:22> col:22 typename depth 1 index 0 Uy
106 template <typename Ty
>
107 template <typename Uy
>
108 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} parent 0x{{[^ ]*}} prev 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:18> col:13 f
109 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 1 index 0 Uy
113 template <class T
> struct C
{
114 template <class U
> using type1
= U(T
);
116 using type2
= typename C
<int>::type1
<void>;
117 // CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, col:42> col:7 type2 'typename C<int>::type1<void>':'void (int)'
118 // CHECK-NEXT: ElaboratedType 0x{{[^ ]*}} 'typename C<int>::type1<void>' sugar
119 // CHECK-NEXT: TemplateSpecializationType 0x{{[^ ]*}} 'type1<void>' sugar alias type1
120 // CHECK-NEXT: TemplateArgument type 'void'
121 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
122 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
123 // CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
124 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
125 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
126 // CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
127 // CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
128 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
129 } // namespace PR55886
132 template <typename
... As
> struct Y
;
133 template <typename
... Bs
> using Z
= Y
<Bs
...>;
134 template <typename
... Cs
> struct foo
{
135 template <typename
... Ds
> using bind
= Z
<Ds
..., Cs
...>;
137 using t1
= foo
<int, short>::bind
<char, float>;
138 // CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'Y<char, float, int, short>' sugar Y
139 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... Bs pack_index 3
140 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
141 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... Bs pack_index 2
142 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
143 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... Bs pack_index 1
144 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
145 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... Bs pack_index 0
146 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
148 template <typename
... T
> struct D
{
149 template <typename
... U
> using B
= int(int (*...p
)(T
, U
));
151 using t2
= D
<float, char>::B
<int, short>;
152 // CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'B<int, short>' sugar alias B
153 // CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int (*)(char, short))' cdecl
154 // CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (float, int)' cdecl
155 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... T pack_index 1
156 // CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
157 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... U pack_index 1
158 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
159 // CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (char, short)' cdecl
160 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... T pack_index 0
161 // CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
162 // CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... U pack_index 0
163 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
164 } // namespace PR56099
166 namespace subst_default_argument
{
167 template<class A1
> class A
{};
168 template<template<class C1
, class C2
= A
<C1
>> class D1
, class D2
> using D
= D1
<D2
>;
170 template<class E1
, class E2
> class E
{};
171 using test1
= D
<E
, int>;
172 // CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[1-9]+}}:1, col:23> col:7 test1 'D<subst_default_argument::E, int>':'subst_default_argument::E<int, subst_default_argument::A<int>>'
173 // CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'A<int>' sugar A
174 // CHECK-NEXT: |-TemplateArgument type 'int'
175 // CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 1 D2
176 // CHECK-NEXT: | |-TypeAliasTemplate 0x{{[^ ]*}} 'D'
177 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
178 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A<int>'
179 // CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
180 } // namespace subst_default_argument
185 // CHECK:VarTemplateDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:13> col:3 unTempl
186 // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 T
187 // CHECK-NEXT: |-VarDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:13> col:3 unTempl 'T' cinit
188 // CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}} <col:13> 'int' 1
192 // FIXME (#61680) - serializing and loading AST should not affect reported source range
193 // DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:16> col:5 unTempl 'int'
194 // SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:5> col:5 unTempl 'int'
195 // CHECK-NEXT: `-TemplateArgument type 'int'
196 // CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
199 float unTempl
<float> = 1;
200 // CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:24> col:7 unTempl 'float' cinit
201 // CHECK-NEXT: |-TemplateArgument type 'float'
202 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
203 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <col:24> 'float' <IntegralToFloating>
204 // CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:24> 'int' 1
206 template<class T
, class U
>
208 // CHECK: VarTemplateDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:14> col:3 binTempl
209 // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 T
210 // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <col:19, col:25> col:25 class depth 0 index 1 U
211 // CHECK-NEXT: |-VarDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:14> col:3 binTempl 'T' cinit
212 // CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}} <col:14> 'int' 1
215 int binTempl
<int, U
>;
216 // CHECK: VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:20> col:5 binTempl 'int'
217 // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 U
218 // CHECK-NEXT: |-TemplateArgument type 'int'
219 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
220 // CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
221 // CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0
224 float binTempl
<float, U
> = 1;
225 // CHECK: VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:24> col:7 binTempl 'float' cinit
226 // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 U
227 // CHECK-NEXT: |-TemplateArgument type 'float'
228 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
229 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
230 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0
231 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <line:{{[0-9]+}}:28> 'float' <IntegralToFloating>
232 // CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:28> 'int' 1
235 int binTempl
<int, int>;
236 // FIXME (#61680) - serializing and loading AST should not affect reported source range
237 // DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:22> col:5 binTempl 'int'
238 // SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:5> col:5 binTempl 'int'
239 // CHECK-NEXT: |-TemplateArgument type 'int'
240 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
241 // CHECK-NEXT: `-TemplateArgument type 'int'
242 // CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
245 float binTempl
<float, float> = 1;
246 // CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:32> col:7 binTempl 'float' cinit
247 // CHECK-NEXT: |-TemplateArgument type 'float'
248 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
249 // CHECK-NEXT: |-TemplateArgument type 'float'
250 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
251 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <col:32> 'float' <IntegralToFloating>
252 // CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:32> 'int' 1