Home | History | Annotate | Download | only in Misc
      1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -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 thread_local int TestThreadLocalInt;
     96 // CHECK: TestThreadLocalInt {{.*}} tls_dynamic
     97 
     98 __module_private__ class TestCXXRecordDeclPrivate;
     99 // CHECK: CXXRecordDecl{{.*}} class TestCXXRecordDeclPrivate __module_private__
    100 
    101 class testCXXMethodDecl {
    102   __module_private__ void TestCXXMethodDeclPrivate();
    103   virtual void TestCXXMethodDeclPure() = 0;
    104   void TestCXXMethodDeclDelete() = delete;
    105   void TestCXXMethodDeclThrow() throw();
    106   void TestCXXMethodDeclThrowType() throw(int);
    107 };
    108 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPrivate 'void (void)' __module_private__
    109 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPure 'void (void)' virtual pure
    110 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclDelete 'void (void)' delete
    111 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrow 'void (void) throw()'
    112 // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrowType 'void (void) throw(int)'
    113 
    114 namespace testCXXConstructorDecl {
    115   class A { };
    116   class TestCXXConstructorDecl : public A {
    117     int I;
    118     TestCXXConstructorDecl(A &a, int i) : A(a), I(i) { }
    119   };
    120 }
    121 // CHECK:      CXXConstructorDecl{{.*}} TestCXXConstructorDecl 'void {{.*}}'
    122 // CHECK-NEXT:   ParmVarDecl{{.*}} a
    123 // CHECK-NEXT:   ParmVarDecl{{.*}} i
    124 // CHECK-NEXT:   CXXCtorInitializer{{.*}}A
    125 // CHECK-NEXT:     Expr
    126 // CHECK:        CXXCtorInitializer{{.*}}I
    127 // CHECK-NEXT:     Expr
    128 // CHECK:        CompoundStmt
    129 
    130 class TestCXXDestructorDecl {
    131   ~TestCXXDestructorDecl() { }
    132 };
    133 // CHECK:      CXXDestructorDecl{{.*}} ~TestCXXDestructorDecl 'void (void) noexcept'
    134 // CHECK-NEXT:   CompoundStmt
    135 
    136 class TestCXXConversionDecl {
    137   operator int() { return 0; }
    138 };
    139 // CHECK:      CXXConversionDecl{{.*}} operator int 'int (void)'
    140 // CHECK-NEXT:   CompoundStmt
    141 
    142 namespace TestStaticAssertDecl {
    143   static_assert(true, "msg");
    144 }
    145 // CHECK:      NamespaceDecl{{.*}} TestStaticAssertDecl
    146 // CHECK-NEXT:   StaticAssertDecl{{.*>$}}
    147 // CHECK-NEXT:     CXXBoolLiteralExpr
    148 // CHECK-NEXT:     StringLiteral
    149 
    150 namespace testFunctionTemplateDecl {
    151   class A { };
    152   class B { };
    153   class C { };
    154   class D { };
    155   template<typename T> void TestFunctionTemplate(T) { }
    156 
    157   // implicit instantiation
    158   void bar(A a) { TestFunctionTemplate(a); }
    159 
    160   // explicit specialization
    161   template<> void TestFunctionTemplate(B);
    162 
    163   // explicit instantiation declaration
    164   extern template void TestFunctionTemplate(C);
    165 
    166   // explicit instantiation definition
    167   template void TestFunctionTemplate(D);
    168 }
    169 // CHECK:      FunctionTemplateDecl{{.*}} TestFunctionTemplate
    170 // CHECK-NEXT:   TemplateTypeParmDecl
    171 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate 'void (T)'
    172 // CHECK-NEXT:     ParmVarDecl{{.*}} 'T'
    173 // CHECK-NEXT:     CompoundStmt
    174 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}A
    175 // CHECK-NEXT:     TemplateArgument
    176 // CHECK-NEXT:     ParmVarDecl
    177 // CHECK-NEXT:     CompoundStmt
    178 // CHECK-NEXT:   Function{{.*}} 'TestFunctionTemplate' {{.*}}B
    179 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}C
    180 // CHECK-NEXT:     TemplateArgument
    181 // CHECK-NEXT:     ParmVarDecl
    182 // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}D
    183 // CHECK-NEXT:     TemplateArgument
    184 // CHECK-NEXT:     ParmVarDecl
    185 // CHECK-NEXT:     CompoundStmt
    186 // CHECK:      FunctionDecl{{.*}} TestFunctionTemplate {{.*}}B
    187 // CHECK-NEXT:   TemplateArgument
    188 // CHECK-NEXT:   ParmVarDecl
    189 
    190 namespace testClassTemplateDecl {
    191   class A { };
    192   class B { };
    193   class C { };
    194   class D { };
    195 
    196   template<typename T> class TestClassTemplate {
    197     int i;
    198   };
    199 
    200   // implicit instantiation
    201   TestClassTemplate<A> a;
    202 
    203   // explicit specialization
    204   template<> class TestClassTemplate<B> {
    205     int j;
    206   };
    207 
    208   // explicit instantiation declaration
    209   extern template class TestClassTemplate<C>;
    210 
    211   // explicit instantiation definition
    212   template class TestClassTemplate<D>;
    213 
    214   // partial explicit specialization
    215   template<typename T1, typename T2> class TestClassTemplatePartial {
    216     int i;
    217   };
    218   template<typename T1> class TestClassTemplatePartial<T1, A> {
    219     int j;
    220   };
    221 }
    222 // CHECK:      ClassTemplateDecl{{.*}} TestClassTemplate
    223 // CHECK-NEXT:   TemplateTypeParmDecl
    224 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    225 // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    226 // CHECK-NEXT:     FieldDecl{{.*}} i
    227 // CHECK-NEXT:   ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    228 // CHECK-NEXT:     TemplateArgument{{.*}}A
    229 // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    230 // CHECK-NEXT:     FieldDecl{{.*}} i
    231 // CHECK:        ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    232 // CHECK-NEXT:   ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    233 // CHECK-NEXT:   ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    234 
    235 // CHECK:      ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    236 // CHECK-NEXT:   TemplateArgument{{.*}}B
    237 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    238 // CHECK-NEXT:   FieldDecl{{.*}} j
    239 
    240 // CHECK:      ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    241 // CHECK-NEXT:   TemplateArgument{{.*}}C
    242 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    243 // CHECK-NEXT:   FieldDecl{{.*}} i
    244 
    245 // CHECK:      ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    246 // CHECK-NEXT:   TemplateArgument{{.*}}D
    247 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    248 // CHECK-NEXT:   FieldDecl{{.*}} i
    249 
    250 // CHECK:      ClassTemplatePartialSpecializationDecl{{.*}} class TestClassTemplatePartial
    251 // CHECK-NEXT:   TemplateArgument
    252 // CHECK-NEXT:   TemplateArgument{{.*}}A
    253 // CHECK-NEXT:   TemplateTypeParmDecl
    254 // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplatePartial
    255 // CHECK-NEXT:   FieldDecl{{.*}} j
    256 
    257 // PR15220 dump instantiation only once
    258 namespace testCanonicalTemplate {
    259   class A {};
    260 
    261   template<typename T> void TestFunctionTemplate(T);
    262   template<typename T> void TestFunctionTemplate(T);
    263   void bar(A a) { TestFunctionTemplate(a); }
    264   // CHECK:      FunctionTemplateDecl{{.*}} TestFunctionTemplate
    265   // CHECK-NEXT:   TemplateTypeParmDecl
    266   // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate 'void (T)'
    267   // CHECK-NEXT:     ParmVarDecl{{.*}} 'T'
    268   // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate {{.*}}A
    269   // CHECK-NEXT:     TemplateArgument
    270   // CHECK-NEXT:     ParmVarDecl
    271   // CHECK:      FunctionTemplateDecl{{.*}} TestFunctionTemplate
    272   // CHECK-NEXT:   TemplateTypeParmDecl
    273   // CHECK-NEXT:   FunctionDecl{{.*}} TestFunctionTemplate 'void (T)'
    274   // CHECK-NEXT:     ParmVarDecl{{.*}} 'T'
    275   // CHECK-NEXT:   Function{{.*}} 'TestFunctionTemplate'
    276   // CHECK-NEXT-NOT: TemplateArgument
    277 
    278   template<typename T1> class TestClassTemplate {
    279     template<typename T2> friend class TestClassTemplate;
    280   };
    281   TestClassTemplate<A> a;
    282   // CHECK:      ClassTemplateDecl{{.*}} TestClassTemplate
    283   // CHECK-NEXT:   TemplateTypeParmDecl
    284   // CHECK-NEXT:   CXXRecordDecl{{.*}} class TestClassTemplate
    285   // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    286   // CHECK-NEXT:     FriendDecl
    287   // CHECK-NEXT:       ClassTemplateDecl{{.*}} TestClassTemplate
    288   // CHECK-NEXT:         TemplateTypeParmDecl
    289   // CHECK-NEXT:         CXXRecordDecl{{.*}} class TestClassTemplate
    290   // CHECK-NEXT:         ClassTemplateSpecialization{{.*}} 'TestClassTemplate'
    291   // CHECK-NEXT:   ClassTemplateSpecializationDecl{{.*}} class TestClassTemplate
    292   // CHECK-NEXT:     TemplateArgument{{.*}}A
    293   // CHECK-NEXT:     CXXRecordDecl{{.*}} class TestClassTemplate
    294 }
    295 
    296 template <class T>
    297 class TestClassScopeFunctionSpecialization {
    298   template<class U> void foo(U a) { }
    299   template<> void foo<int>(int a) { }
    300 };
    301 // CHECK:      ClassScopeFunctionSpecializationDecl
    302 // CHECK-NEXT:   CXXMethod{{.*}} 'foo' 'void (int)'
    303 // CHECK-NEXT:   TemplateArgument{{.*}} 'int'
    304 
    305 namespace TestTemplateTypeParmDecl {
    306   template<typename ... T, class U = int> void foo();
    307 }
    308 // CHECK:      NamespaceDecl{{.*}} TestTemplateTypeParmDecl
    309 // CHECK-NEXT:   FunctionTemplateDecl
    310 // CHECK-NEXT:     TemplateTypeParmDecl{{.*}} typename ... T
    311 // CHECK-NEXT:     TemplateTypeParmDecl{{.*}} class U 'int'
    312 
    313 namespace TestNonTypeTemplateParmDecl {
    314   template<int I = 1, int ... J> void foo();
    315 }
    316 // CHECK:      NamespaceDecl{{.*}} TestNonTypeTemplateParmDecl
    317 // CHECK-NEXT:   FunctionTemplateDecl
    318 // CHECK-NEXT:     NonTypeTemplateParmDecl{{.*}} 'int' I
    319 // CHECK-NEXT:       IntegerLiteral{{.*}} 'int' 1
    320 // CHECK-NEXT:     NonTypeTemplateParmDecl{{.*}} 'int' ... J
    321 
    322 namespace TestTemplateTemplateParmDecl {
    323   template<typename T> class A;
    324   template <template <typename> class T = A, template <typename> class ... U> void foo();
    325 }
    326 // CHECK:      NamespaceDecl{{.*}} TestTemplateTemplateParmDecl
    327 // CHECK:        FunctionTemplateDecl
    328 // CHECK-NEXT:     TemplateTemplateParmDecl{{.*}} T
    329 // CHECK-NEXT:       TemplateTypeParmDecl{{.*}} typename
    330 // CHECK-NEXT:       TemplateArgument{{.*}} template A
    331 // CHECK-NEXT:     TemplateTemplateParmDecl{{.*}} ... U
    332 // CHECK-NEXT:       TemplateTypeParmDecl{{.*}} typename
    333 
    334 namespace TestTemplateArgument {
    335   template<typename> class A { };
    336   template<template<typename> class ...> class B { };
    337   int foo();
    338 
    339   template<typename> class testType { };
    340   template class testType<int>;
    341   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testType
    342   // CHECK-NEXT:   TemplateArgument{{.*}} type 'int'
    343 
    344   template<int fp(void)> class testDecl { };
    345   template class testDecl<foo>;
    346   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testDecl
    347   // CHECK-NEXT:   TemplateArgument{{.*}} decl
    348   // CHECK-NEXT:     Function{{.*}}foo
    349 
    350   template class testDecl<nullptr>;
    351   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testDecl
    352   // CHECK-NEXT:   TemplateArgument{{.*}} nullptr
    353 
    354   template<int> class testIntegral { };
    355   template class testIntegral<1>;
    356   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testIntegral
    357   // CHECK-NEXT:   TemplateArgument{{.*}} integral 1
    358 
    359   template<template<typename> class> class testTemplate { };
    360   template class testTemplate<A>;
    361   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testTemplate
    362   // CHECK-NEXT:   TemplateArgument{{.*}} A
    363 
    364   template<template<typename> class ...T> class C {
    365     B<T...> testTemplateExpansion;
    366   };
    367   // FIXME: Need TemplateSpecializationType dumping to test TemplateExpansion.
    368 
    369   template<int, int = 0> class testExpr;
    370   template<int I> class testExpr<I> { };
    371   // CHECK:      ClassTemplatePartialSpecializationDecl{{.*}} class testExpr
    372   // CHECK-NEXT:   TemplateArgument{{.*}} expr
    373   // CHECK-NEXT:     DeclRefExpr{{.*}}I
    374 
    375   template<int, int ...> class testPack { };
    376   template class testPack<0, 1, 2>;
    377   // CHECK:      ClassTemplateSpecializationDecl{{.*}} class testPack
    378   // CHECK-NEXT:   TemplateArgument{{.*}} integral 0
    379   // CHECK-NEXT:   TemplateArgument{{.*}} pack
    380   // CHECK-NEXT:     TemplateArgument{{.*}} integral 1
    381   // CHECK-NEXT:     TemplateArgument{{.*}} integral 2
    382 }
    383 
    384 namespace testUsingDecl {
    385   int i;
    386 }
    387 namespace TestUsingDecl {
    388   using testUsingDecl::i;
    389 }
    390 // CHECK:      NamespaceDecl{{.*}} TestUsingDecl
    391 // CHECK-NEXT:   UsingDecl{{.*}} testUsingDecl::i
    392 // CHECK-NEXT:   UsingShadowDecl{{.*}} Var{{.*}} 'i' 'int'
    393 
    394 namespace testUnresolvedUsing {
    395   class A { };
    396   template<class T> class B {
    397   public:
    398     A a;
    399   };
    400   template<class T> class TestUnresolvedUsing : public B<T> {
    401     using typename B<T>::a;
    402     using B<T>::a;
    403   };
    404 }
    405 // CHECK: CXXRecordDecl{{.*}} TestUnresolvedUsing
    406 // CHECK:   UnresolvedUsingTypenameDecl{{.*}} B<T>::a
    407 // CHECK:   UnresolvedUsingValueDecl{{.*}} B<T>::a
    408 
    409 namespace TestLinkageSpecDecl {
    410   extern "C" void test1();
    411   extern "C++" void test2();
    412 }
    413 // CHECK:      NamespaceDecl{{.*}} TestLinkageSpecDecl
    414 // CHECK-NEXT:   LinkageSpecDecl{{.*}} C
    415 // CHECK-NEXT:     FunctionDecl
    416 // CHECK-NEXT:   LinkageSpecDecl{{.*}} C++
    417 // CHECK-NEXT:     FunctionDecl
    418 
    419 class TestAccessSpecDecl {
    420 public:
    421 private:
    422 protected:
    423 };
    424 // CHECK:      CXXRecordDecl{{.*}} class TestAccessSpecDecl
    425 // CHECK-NEXT:    CXXRecordDecl{{.*}} class TestAccessSpecDecl
    426 // CHECK-NEXT:    AccessSpecDecl{{.*}} public
    427 // CHECK-NEXT:    AccessSpecDecl{{.*}} private
    428 // CHECK-NEXT:    AccessSpecDecl{{.*}} protected
    429 
    430 template<typename T> class TestFriendDecl {
    431   friend int foo();
    432   friend class A;
    433   friend T;
    434 };
    435 // CHECK:      CXXRecord{{.*}} TestFriendDecl
    436 // CHECK-NEXT:   CXXRecord{{.*}} TestFriendDecl
    437 // CHECK-NEXT:   FriendDecl
    438 // CHECK-NEXT:     FunctionDecl{{.*}} foo
    439 // CHECK-NEXT:   FriendDecl{{.*}} 'class A':'class A'
    440 // CHECK-NEXT:   FriendDecl{{.*}} 'T'
    441 
    442 namespace TestFileScopeAsmDecl {
    443   asm("ret");
    444 }
    445 // CHECK:      NamespaceDecl{{.*}} TestFileScopeAsmDecl{{$}}
    446 // CHECK:        FileScopeAsmDecl{{.*>$}}
    447 // CHECK-NEXT:     StringLiteral
    448 
    449 namespace TestFriendDecl2 {
    450   void f();
    451   struct S {
    452     friend void f();
    453   };
    454 }
    455 // CHECK: NamespaceDecl [[TestFriendDecl2:0x.*]] <{{.*}}> TestFriendDecl2
    456 // CHECK: |-FunctionDecl [[TestFriendDecl2_f:0x.*]] <{{.*}}> f 'void (void)'
    457 // CHECK: `-CXXRecordDecl {{.*}} struct S
    458 // CHECK:   |-CXXRecordDecl {{.*}} struct S
    459 // CHECK:   `-FriendDecl
    460 // CHECK:     `-FunctionDecl {{.*}} parent [[TestFriendDecl2]] prev [[TestFriendDecl2_f]] <{{.*}}> f 'void (void)'
    461 
    462 namespace Comment {
    463   extern int Test;
    464   /// Something here.
    465   extern int Test;
    466   extern int Test;
    467 }
    468 
    469 // CHECK: VarDecl {{.*}} Test 'int' extern
    470 // CHECK-NOT: FullComment
    471 // CHECK: VarDecl {{.*}} Test 'int' extern
    472 // CHECK: `-FullComment
    473 // CHECK:   `-ParagraphComment
    474 // CHECK:       `-TextComment
    475 // CHECK: VarDecl {{.*}} Test 'int' extern
    476 // CHECK-NOT: FullComment
    477