242 lines · cpp
1// Test without serialization:2// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \3// RUN: | FileCheck -strict-whitespace %s4//5// Test with serialization:6// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s7// 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 %s10 11template <typename Ty>12// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> col:6 a13// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty14void a(Ty);15 16template <typename... Ty>17// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:13> col:6 b18// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:23> col:23 referenced typename depth 0 index 0 ... Ty19void b(Ty...);20 21template <typename Ty, typename Uy>22// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:14> col:6 c23// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty24// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <col:24, col:33> col:33 referenced typename depth 0 index 1 Uy25void c(Ty, Uy);26 27template <>28void 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'32 33template <typename Ty, template<typename> typename Uy>34// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+4]]:18> col:6 d35// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 referenced typename depth 0 index 0 Ty36// CHECK-NEXT: TemplateTemplateParmDecl 0x{{[^ ]*}} <col:24, col:52> col:52 depth 0 index 1 Uy37// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <col:33> col:41 typename depth 1 index 038void d(Ty, Uy<Ty>);39 40template <class Ty>41// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:10> col:6 e42// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:17> col:17 referenced class depth 0 index 0 Ty43void e(Ty);44 45template <int N>46// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:17> col:6 f47// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:15> col:15 referenced 'int' depth 0 index 0 N48void f(int i = N);49 50template <typename Ty = int>51// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:10> col:6 g52// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:25> col:20 referenced typename depth 0 index 0 Ty53// CHECK-NEXT: TemplateArgument type 'int'54void g(Ty);55 56template <typename = void>57// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:8> col:6 h58// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:22> col:20 typename depth 0 index 059// CHECK-NEXT: TemplateArgument type 'void'60void h();61 62template <typename Ty>63// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:11> col:8 R64// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 0 index 0 Ty65// CHECK: ClassTemplateSpecialization 0x{{[^ ]*}} 'R'66struct R {};67 68template <>69// CHECK: ClassTemplateSpecializationDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:16> col:8 struct R definition70// CHECK: TemplateArgument type 'int'71struct R<int> {};72 73template <typename Ty, class Uy>74// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:11> col:8 S75// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 0 index 0 Ty76// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <col:24, col:30> col:30 class depth 0 index 1 Uy77struct S {};78 79template <typename Ty>80// CHECK: ClassTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+4]]:20> col:8 struct S definition81// 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 Ty84struct S<Ty, int> {};85 86template <auto>87// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:11> col:8 T88// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11> col:15 'auto' depth 0 index 089struct T {};90 91template <decltype(auto)>92// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:11> col:8 U93// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:24> col:25 'decltype(auto)' depth 0 index 094struct U {};95 96template <typename Ty>97// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+7]]:1> line:[[@LINE+2]]:8 V98// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 0 index 0 Ty99struct V {100 template <typename Uy>101 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, line:[[@LINE+2]]:10> col:8 f102 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:13, col:22> col:22 typename depth 1 index 0 Uy103 void f();104};105 106template <typename Ty>107template <typename Uy>108// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} parent 0x{{[^ ]*}} prev 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:18> col:13 f109// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:20> col:20 typename depth 1 index 0 Uy110void V<Ty>::f() {}111 112namespace PR55886 {113template <class T> struct C {114 template <class U> using type1 = U(T);115};116using 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: TemplateSpecializationType 0x{{[^ ]*}} 'typename C<int>::type1<void>' sugar alias119// CHECK-NEXT: name: 'C<int>::type1':'PR55886::C<int>::type1' qualified120// CHECK-NEXT: NestedNameSpecifier TypeSpec 'C<int>':'PR55886::C<int>'121// CHECK-NEXT: TypeAliasTemplateDecl {{.+}} type1122// CHECK-NEXT: TemplateArgument type 'void'123// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'124// CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl125// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U final126// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'127// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'128// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T129// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'130// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'131} // namespace PR55886132 133namespace PR56099 {134template <typename... T> struct D {135 template <typename... U> struct bind {136 using bound_type = int(int (*...p)(T, U));137 };138};139template struct D<float, char>::bind<int, short>;140// CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[1-9]+}}:5, col:45> col:11 bound_type 'int (int (*)(float, int), int (*)(char, short))'141// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int (*)(char, short))' cdecl142// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (float, int)' cdecl143// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... T pack_index 1{{$}}144// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'145// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... U pack_index 1{{$}}146// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'bind'147// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (char, short)' cdecl148// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... T pack_index 0{{$}}149// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'150// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... U pack_index 0{{$}}151// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'bind'152} // namespace PR56099153 154namespace subst_default_argument {155template<class A1> class A {};156template<template<class C1, class C2 = A<C1>> class D1, class D2> using D = D1<D2>;157 158template<class E1, class E2> class E {};159using test1 = D<E, int>;160// CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:23> col:7 test1 'D<E, int>':'subst_default_argument::E<int, subst_default_argument::A<int>>'161// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'A<int>' sugar162// CHECK-NEXT: |-name: 'A':'subst_default_argument::A' qualified163// CHECK-NEXT: | `-ClassTemplateDecl {{.+}} A164// CHECK-NEXT: |-TemplateArgument type 'int'165// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 E1 final166// CHECK-NEXT: | |-ClassTemplate 0x{{[^ ]*}} 'E'167// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 1 D2 final168// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[^ ]*}} 'D'169// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'170// CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A<int>'171// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'172} // namespace subst_default_argument173 174namespace D146733 {175template<class T>176T unTempl = 1;177// CHECK:VarTemplateDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:13> col:3 unTempl178// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 T179// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:13> col:3 unTempl 'T' cinit180// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}} <col:13> 'int' 1181 182template<>183int unTempl<int>;184// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:16> col:5 unTempl 'int'185// CHECK-NEXT: `-TemplateArgument type 'int'186// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'187 188template<>189float unTempl<float> = 1;190// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:24> col:7 unTempl 'float'191// CHECK-NEXT: |-TemplateArgument type 'float'192// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'193// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <col:24> 'float' <IntegralToFloating>194// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:24> 'int' 1195 196template<class T, class U>197T binTempl = 1;198// CHECK: VarTemplateDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:14> col:3 binTempl199// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 T200// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <col:19, col:25> col:25 class depth 0 index 1 U201// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:14> col:3 binTempl 'T' cinit202// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}} <col:14> 'int' 1203 204template<class U>205int binTempl<int, U>;206// CHECK: VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:20> col:5 binTempl 'int'207// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 U208// CHECK-NEXT: |-TemplateArgument type 'int'209// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'210// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'211// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0212 213template<class U>214float binTempl<float, U> = 1;215// CHECK: VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:28> col:7 binTempl 'float'216// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 U217// CHECK-NEXT: |-TemplateArgument type 'float'218// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'219// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'220// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0221// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <line:{{[0-9]+}}:28> 'float' <IntegralToFloating>222// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:28> 'int' 1223 224template<>225int binTempl<int, int>;226// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:22> col:5 binTempl 'int'227// CHECK-NEXT: |-TemplateArgument type 'int'228// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'229// CHECK-NEXT: `-TemplateArgument type 'int'230// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'231 232template<>233float binTempl<float, float> = 1;234// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:32> col:7 binTempl 'float'235// CHECK-NEXT: |-TemplateArgument type 'float'236// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'237// CHECK-NEXT: |-TemplateArgument type 'float'238// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'239// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <col:32> 'float' <IntegralToFloating>240// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:32> 'int' 1241}242