Home | History | Annotate | Download | only in Misc
      1 // RUN: %clang_cc1 -std=c++11 -fms-extensions -ast-dump -ast-dump-filter Test %s | FileCheck -check-prefix CHECK -strict-whitespace %s
      2 
      3 class testEnumDecl {
      4   enum class TestEnumDeclScoped;
      5   enum TestEnumDeclFixed : int;
      6 };
      7 // CHECK: EnumDecl{{.*}} class TestEnumDeclScoped 'int'
      8 // CHECK: EnumDecl{{.*}} TestEnumDeclFixed 'int'
      9 
     10 class testFieldDecl {
     11   int TestFieldDeclInit = 0;
     12 };
     13 // CHECK:      FieldDecl{{.*}} TestFieldDeclInit 'int'
     14 // CHECK-NEXT:   IntegerLiteral
     15 
     16 namespace testVarDeclNRVO {
     17   class A { };
     18   A foo() {
     19     A TestVarDeclNRVO;
     20     return TestVarDeclNRVO;
     21   }
     22 }
     23 // CHECK: VarDecl{{.*}} TestVarDeclNRVO 'class testVarDeclNRVO::A' nrvo
     24 
     25 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
     26 // CHECK:      ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
     27 // CHECK-NEXT:   IntegerLiteral{{.*}}
     28 
     29 namespace TestNamespaceDecl {
     30   int i;
     31 }
     32 // CHECK:      NamespaceDecl{{.*}} TestNamespaceDecl
     33 // CHECK-NEXT:   VarDecl
     34 
     35 namespace TestNamespaceDecl {
     36   int j;
     37 }
     38 // CHECK:      NamespaceDecl{{.*}} TestNamespaceDecl
     39 // CHECK-NEXT:   original Namespace
     40 // CHECK-NEXT:   VarDecl
     41 
     42 inline namespace TestNamespaceDeclInline {
     43 }
     44 // CHECK:      NamespaceDecl{{.*}} TestNamespaceDeclInline inline
     45 
     46 namespace testUsingDirectiveDecl {
     47   namespace A {
     48   }
     49 }
     50 namespace TestUsingDirectiveDecl {
     51   using namespace testUsingDirectiveDecl::A;
     52 }
     53 // CHECK:      NamespaceDecl{{.*}} TestUsingDirectiveDecl
     54 // CHECK-NEXT:   UsingDirectiveDecl{{.*}} Namespace{{.*}} 'A'
     55 
     56 namespace testNamespaceAlias {
     57   namespace A {
     58   }
     59 }
     60 namespace TestNamespaceAlias = testNamespaceAlias::A;
     61 // CHECK:      NamespaceAliasDecl{{.*}} TestNamespaceAlias
     62 // CHECK-NEXT:   Namespace{{.*}} 'A'
     63 
     64 using TestTypeAliasDecl = int;
     65 // CHECK: TypeAliasDecl{{.*}} TestTypeAliasDecl 'int'
     66 
     67 namespace testTypeAliasTemplateDecl {
     68   template<typename T> class A;
     69   template<typename T> using TestTypeAliasTemplateDecl = A<T>;
     70 }
     71 // CHECK:      TypeAliasTemplateDecl{{.*}} TestTypeAliasTemplateDecl
     72 // CHECK-NEXT:   TemplateTypeParmDecl
     73 // CHECK-NEXT:   TypeAliasDecl{{.*}} TestTypeAliasTemplateDecl 'A<T>'
     74 
     75 namespace testCXXRecordDecl {
     76   class A { };
     77   class B { };
     78   class TestCXXRecordDecl : virtual A, public B {
     79     int i;
     80   };
     81 }
     82 // CHECK:      CXXRecordDecl{{.*}} class TestCXXRecordDecl
     83 // CHECK-NEXT:   virtual private 'class testCXXRecordDecl::A'
     84 // CHECK-NEXT:   public 'class testCXXRecordDecl::B'
     85 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestCXXRecordDecl
     86 // CHECK-NEXT:   FieldDecl
     87 
     88 template<class...T>
     89 class TestCXXRecordDeclPack : public T... {
     90 };
     91 // CHECK:      CXXRecordDecl{{.*}} class TestCXXRecordDeclPack
     92 // CHECK-NEXT:   public 'T'...
     93 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestCXXRecordDeclPack
     94 
     95 __module_private__ class TestCXXRecordDeclPrivate;
     96 // CHECK: CXXRecordDecl{{.*}} class TestCXXRecordDeclPrivate __module_private__
     97 
     98 class testCXXMethodDecl {
     99   __module_private__ void TestCXXMethodDeclPrivate();
    100   virtual void TestCXXMethodDeclPure() = 0;
    101   void TestCXXMethodDeclDelete() = delete;
    102   void TestCXXMethodDeclThrow() throw();
    103   void TestCXXMethodDeclThrowType() throw(int);
    104 };
    105 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPrivate 'void (void)' __module_private__
    106 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPure 'void (void)' virtual pure
    107 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclDelete 'void (void)' delete
    108 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrow 'void (void) throw()'
    109 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrowType 'void (void) throw(int)'
    110 
    111 namespace testCXXConstructorDecl {
    112   class A { };
    113   class TestCXXConstructorDecl : public A {
    114     int I;
    115     TestCXXConstructorDecl(A &a, int i) : A(a), I(i) { }
    116   };
    117 }
    118 // CHECK:      CXXConstructorDecl{{.*}} TestCXXConstructorDecl 'void {{.*}}'
    119 // CHECK-NEXT:   ParmVarDecl{{.*}} a
    120 // CHECK-NEXT:   ParmVarDecl{{.*}} i
    121 // CHECK-NEXT:   CXXCtorInitializer{{.*}}A
    122 // CHECK-NEXT:     Expr
    123 // CHECK:        CXXCtorInitializer{{.*}}I
    124 // CHECK-NEXT:     Expr
    125 // CHECK:        CompoundStmt
    126 
    127 class TestCXXDestructorDecl {
    128   ~TestCXXDestructorDecl() { }
    129 };
    130 // CHECK:      CXXDestructorDecl{{.*}} ~TestCXXDestructorDecl 'void (void) noexcept'
    131 // CHECK-NEXT:   CompoundStmt
    132 
    133 class TestCXXConversionDecl {
    134   operator int() { return 0; }
    135 };
    136 // CHECK:      CXXConversionDecl{{.*}} operator int 'int (void)'
    137 // CHECK-NEXT:   CompoundStmt
    138 
    139 namespace TestStaticAssertDecl {
    140   static_assert(true, "msg");
    141 }
    142 // CHECK:      NamespaceDecl{{.*}} TestStaticAssertDecl
    143 // CHECK-NEXT:   StaticAssertDecl{{.*>$}}
    144 // CHECK-NEXT:     CXXBoolLiteralExpr
    145 // CHECK-NEXT:     StringLiteral
    146 
    147 namespace testFunctionTemplateDecl {
    148   class A { };
    149   class B { };
    150   class C { };
    151   class D { };
    152   template<typename T> void TestFunctionTemplate(T) { }
    153 
    154   // implicit instantiation
    155   void bar(A a) { TestFunctionTemplate(a); }
    156 
    157   // explicit specialization
    158   template<> void TestFunctionTemplate(B);
    159 
    160   // explicit instantiation declaration
    161   extern template void TestFunctionTemplate(C);
    162 
    163   // explicit instantiation definition
    164   template void TestFunctionTemplate(D);
    165 }
    166 // CHECK:      FunctionTemplateDecl{{.*}} TestFunctionTemplate
    167 // CHECK-NEXT:   TemplateTypeParmDecl
    168 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate 'void (T)'
    169 // CHECK-NEXT:     ParmVarDecl{{.*}} 'T'
    170 // CHECK-NEXT:     CompoundStmt
    171 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}A
    172 // CHECK-NEXT:     TemplateArgument
    173 // CHECK-NEXT:     ParmVarDecl
    174 // CHECK-NEXT:     CompoundStmt
    175 // CHECK-NEXT:   Function{{.*}} 'TestFunctionTemplate' {{.*}}B
    176 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}C
    177 // CHECK-NEXT:     TemplateArgument
    178 // CHECK-NEXT:     ParmVarDecl
    179 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}D
    180 // CHECK-NEXT:     TemplateArgument
    181 // CHECK-NEXT:     ParmVarDecl
    182 // CHECK-NEXT:     CompoundStmt
    183 // CHECK:      FunctionDecl{{.*}} TestFunctionTemplate {{.*}}B
    184 // CHECK-NEXT:   TemplateArgument
    185 // CHECK-NEXT:   ParmVarDecl
    186 
    187 namespace testClassTemplateDecl {
    188   class A { };
    189   class B { };
    190   class C { };
    191   class D { };
    192 
    193   template<typename T> class TestClassTemplate {
    194     int i;
    195   };
    196 
    197   // implicit instantiation
    198   TestClassTemplate<A> a;
    199 
    200   // explicit specialization
    201   template<> class TestClassTemplate<B> {
    202     int j;
    203   };
    204 
    205   // explicit instantiation declaration
    206   extern template class TestClassTemplate<C>;
    207 
    208   // explicit instantiation definition
    209   template class TestClassTemplate<D>;
    210 
    211   // partial explicit specialization
    212   template<typename T1, typename T2> class TestClassTemplatePartial {
    213     int i;
    214   };
    215   template<typename T1> class TestClassTemplatePartial<T1, A> {
    216     int j;
    217   };
    218 }
    219 // CHECK:      ClassTemplateDecl{{.*}} TestClassTemplate
    220 // CHECK-NEXT:   TemplateTypeParmDecl
    221 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    222 // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    223 // CHECK-NEXT:     FieldDecl{{.*}} i
    224 // CHECK-NEXT:   ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    225 // CHECK-NEXT:     TemplateArgument{{.*}}A
    226 // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    227 // CHECK-NEXT:     FieldDecl{{.*}} i
    228 // CHECK:        ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    229 // CHECK-NEXT:   ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    230 // CHECK-NEXT:   ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    231 
    232 // CHECK:      ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    233 // CHECK-NEXT:   TemplateArgument{{.*}}B
    234 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    235 // CHECK-NEXT:   FieldDecl{{.*}} j
    236 
    237 // CHECK:      ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    238 // CHECK-NEXT:   TemplateArgument{{.*}}C
    239 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    240 // CHECK-NEXT:   FieldDecl{{.*}} i
    241 
    242 // CHECK:      ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    243 // CHECK-NEXT:   TemplateArgument{{.*}}D
    244 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    245 // CHECK-NEXT:   FieldDecl{{.*}} i
    246 
    247 // CHECK:      ClassTemplatePartialSpecializationDecl{{.*}} class TestClassTemplatePartial
    248 // CHECK-NEXT:   TemplateArgument
    249 // CHECK-NEXT:   TemplateArgument{{.*}}A
    250 // CHECK-NEXT:   TemplateTypeParmDecl
    251 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplatePartial
    252 // CHECK-NEXT:   FieldDecl{{.*}} j
    253 
    254 // PR15220 dump instantiation only once
    255 namespace testCanonicalTemplate {
    256   class A {};
    257 
    258   template<typename T> void TestFunctionTemplate(T);
    259   template<typename T> void TestFunctionTemplate(T);
    260   void bar(A a) { TestFunctionTemplate(a); }
    261   // CHECK:      FunctionTemplateDecl{{.*}} TestFunctionTemplate
    262   // CHECK-NEXT:   TemplateTypeParmDecl
    263   // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate 'void (T)'
    264   // CHECK-NEXT:     ParmVarDecl{{.*}} 'T'
    265   // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}A
    266   // CHECK-NEXT:     TemplateArgument
    267   // CHECK-NEXT:     ParmVarDecl
    268   // CHECK:      FunctionTemplateDecl{{.*}} TestFunctionTemplate
    269   // CHECK-NEXT:   TemplateTypeParmDecl
    270   // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate 'void (T)'
    271   // CHECK-NEXT:     ParmVarDecl{{.*}} 'T'
    272   // CHECK-NEXT:   Function{{.*}} 'TestFunctionTemplate'
    273   // CHECK-NEXT-NOT: TemplateArgument
    274 
    275   template<typename T1> class TestClassTemplate {
    276     template<typename T2> friend class TestClassTemplate;
    277   };
    278   TestClassTemplate<A> a;
    279   // CHECK:      ClassTemplateDecl{{.*}} TestClassTemplate
    280   // CHECK-NEXT:   TemplateTypeParmDecl
    281   // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    282   // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    283   // CHECK-NEXT:     FriendDecl
    284   // CHECK-NEXT:       ClassTemplateDecl{{.*}} TestClassTemplate
    285   // CHECK-NEXT:         TemplateTypeParmDecl
    286   // CHECK-NEXT:         CXXRecordDecl{{.*}} class TestClassTemplate
    287   // CHECK-NEXT:         ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    288   // CHECK-NEXT:   ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    289   // CHECK-NEXT:     TemplateArgument{{.*}}A
    290   // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    291 }
    292 
    293 template <class T>
    294 class TestClassScopeFunctionSpecialization {
    295   template<class U> void foo(U a) { }
    296   template<> void foo<int>(int a) { }
    297 };
    298 // CHECK:      ClassScopeFunctionSpecializationDecl
    299 // CHECK-NEXT:   CXXMethod{{.*}} 'foo' 'void (int)'
    300 // CHECK-NEXT:   TemplateArgument{{.*}} 'int'
    301 
    302 namespace TestTemplateTypeParmDecl {
    303   template<typename ... T, class U = int> void foo();
    304 }
    305 // CHECK:      NamespaceDecl{{.*}} TestTemplateTypeParmDecl
    306 // CHECK-NEXT:   FunctionTemplateDecl
    307 // CHECK-NEXT:     TemplateTypeParmDecl{{.*}} typename ... T
    308 // CHECK-NEXT:     TemplateTypeParmDecl{{.*}} class U 'int'
    309 
    310 namespace TestNonTypeTemplateParmDecl {
    311   template<int I = 1, int ... J> void foo();
    312 }
    313 // CHECK:      NamespaceDecl{{.*}} TestNonTypeTemplateParmDecl
    314 // CHECK-NEXT:   FunctionTemplateDecl
    315 // CHECK-NEXT:     NonTypeTemplateParmDecl{{.*}} 'int' I
    316 // CHECK-NEXT:       IntegerLiteral{{.*}} 'int' 1
    317 // CHECK-NEXT:     NonTypeTemplateParmDecl{{.*}} 'int' ... J
    318 
    319 namespace TestTemplateTemplateParmDecl {
    320   template<typename T> class A;
    321   template <template <typename> class T = A, template <typename> class ... U> void foo();
    322 }
    323 // CHECK:      NamespaceDecl{{.*}} TestTemplateTemplateParmDecl
    324 // CHECK:        FunctionTemplateDecl
    325 // CHECK-NEXT:     TemplateTemplateParmDecl{{.*}} T
    326 // CHECK-NEXT:       TemplateTypeParmDecl{{.*}} typename
    327 // CHECK-NEXT:       TemplateArgument{{.*}} template A
    328 // CHECK-NEXT:     TemplateTemplateParmDecl{{.*}} ... U
    329 // CHECK-NEXT:       TemplateTypeParmDecl{{.*}} typename
    330 
    331 namespace TestTemplateArgument {
    332   template<typename> class A { };
    333   template<template<typename> class ...> class B { };
    334   int foo();
    335 
    336   template<typename> class testType { };
    337   template class testType<int>;
    338   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testType
    339   // CHECK-NEXT:   TemplateArgument{{.*}} type 'int'
    340 
    341   template<int fp(void)> class testDecl { };
    342   template class testDecl<foo>;
    343   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testDecl
    344   // CHECK-NEXT:   TemplateArgument{{.*}} decl
    345   // CHECK-NEXT:     Function{{.*}}foo
    346 
    347   template class testDecl<nullptr>;
    348   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testDecl
    349   // CHECK-NEXT:   TemplateArgument{{.*}} nullptr
    350 
    351   template<int> class testIntegral { };
    352   template class testIntegral<1>;
    353   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testIntegral
    354   // CHECK-NEXT:   TemplateArgument{{.*}} integral 1
    355 
    356   template<template<typename> class> class testTemplate { };
    357   template class testTemplate<A>;
    358   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testTemplate
    359   // CHECK-NEXT:   TemplateArgument{{.*}} A
    360 
    361   template<template<typename> class ...T> class C {
    362     B<T...> testTemplateExpansion;
    363   };
    364   // FIXME: Need TemplateSpecializationType dumping to test TemplateExpansion.
    365 
    366   template<int, int = 0> class testExpr;
    367   template<int I> class testExpr<I> { };
    368   // CHECK:      ClassTemplatePartialSpecializationDecl{{.*}} class testExpr
    369   // CHECK-NEXT:   TemplateArgument{{.*}} expr
    370   // CHECK-NEXT:     DeclRefExpr{{.*}}I
    371 
    372   template<int, int ...> class testPack { };
    373   template class testPack<0, 1, 2>;
    374   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testPack
    375   // CHECK-NEXT:   TemplateArgument{{.*}} integral 0
    376   // CHECK-NEXT:   TemplateArgument{{.*}} pack
    377   // CHECK-NEXT:     TemplateArgument{{.*}} integral 1
    378   // CHECK-NEXT:     TemplateArgument{{.*}} integral 2
    379 }
    380 
    381 namespace testUsingDecl {
    382   int i;
    383 }
    384 namespace TestUsingDecl {
    385   using testUsingDecl::i;
    386 }
    387 // CHECK:      NamespaceDecl{{.*}} TestUsingDecl
    388 // CHECK-NEXT:   UsingDecl{{.*}} testUsingDecl::i
    389 // CHECK-NEXT:   UsingShadowDecl{{.*}} Var{{.*}} 'i' 'int'
    390 
    391 namespace testUnresolvedUsing {
    392   class A { };
    393   template<class T> class B {
    394   public:
    395     A a;
    396   };
    397   template<class T> class TestUnresolvedUsing : public B<T> {
    398     using typename B<T>::a;
    399     using B<T>::a;
    400   };
    401 }
    402 // CHECK: CXXRecordDecl{{.*}} TestUnresolvedUsing
    403 // CHECK:   UnresolvedUsingTypenameDecl{{.*}} B<T>::a
    404 // CHECK:   UnresolvedUsingValueDecl{{.*}} B<T>::a
    405 
    406 namespace TestLinkageSpecDecl {
    407   extern "C" void test1();
    408   extern "C++" void test2();
    409 }
    410 // CHECK:      NamespaceDecl{{.*}} TestLinkageSpecDecl
    411 // CHECK-NEXT:   LinkageSpecDecl{{.*}} C
    412 // CHECK-NEXT:     FunctionDecl
    413 // CHECK-NEXT:   LinkageSpecDecl{{.*}} C++
    414 // CHECK-NEXT:     FunctionDecl
    415 
    416 class TestAccessSpecDecl {
    417 public:
    418 private:
    419 protected:
    420 };
    421 // CHECK:      CXXRecordDecl{{.*}} class TestAccessSpecDecl
    422 // CHECK-NEXT:    CXXRecordDecl{{.*}} class TestAccessSpecDecl
    423 // CHECK-NEXT:    AccessSpecDecl{{.*}} public
    424 // CHECK-NEXT:    AccessSpecDecl{{.*}} private
    425 // CHECK-NEXT:    AccessSpecDecl{{.*}} protected
    426 
    427 template<typename T> class TestFriendDecl {
    428   friend int foo();
    429   friend class A;
    430   friend T;
    431 };
    432 // CHECK:      CXXRecord{{.*}} TestFriendDecl
    433 // CHECK-NEXT:   CXXRecord{{.*}} TestFriendDecl
    434 // CHECK-NEXT:   FriendDecl
    435 // CHECK-NEXT:     FunctionDecl{{.*}} foo
    436 // CHECK-NEXT:   FriendDecl{{.*}} 'class A':'class A'
    437 // CHECK-NEXT:   FriendDecl{{.*}} 'T'
    438 
    439 namespace TestFileScopeAsmDecl {
    440   asm("ret");
    441 }
    442 // CHECK:      NamespaceDecl{{.*}} TestFileScopeAsmDecl{{$}}
    443 // CHECK:        FileScopeAsmDecl{{.*>$}}
    444 // CHECK-NEXT:     StringLiteral
    445 
    446 namespace TestFriendDecl2 {
    447   void f();
    448   struct S {
    449     friend void f();
    450   };
    451 }
    452 // CHECK: NamespaceDecl [[TestFriendDecl2:0x.*]] <{{.*}}> TestFriendDecl2
    453 // CHECK: |-FunctionDecl [[TestFriendDecl2_f:0x.*]] <{{.*}}> f 'void (void)'
    454 // CHECK: `-CXXRecordDecl {{.*}} struct S
    455 // CHECK:   |-CXXRecordDecl {{.*}} struct S
    456 // CHECK:   `-FriendDecl
    457 // CHECK:     `-FunctionDecl {{.*}} parent [[TestFriendDecl2]] prev [[TestFriendDecl2_f]] <{{.*}}> f 'void (void)'
    458