xref: /llvm-project/clang/test/AST/ast-dump-lookups.cpp (revision 467ed2798772344e2a3b4a8d368575f1f9d1a8c6)
1 // RUN: %clang_cc1 -std=c++11 -ast-dump -ast-dump-filter Test %s | FileCheck -check-prefix DECLS %s
2 // RUN: %clang_cc1 -std=c++11 -ast-dump-lookups -ast-dump-filter Test %s | FileCheck -check-prefix LOOKUPS %s
3 // RUN: %clang_cc1 -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter Test %s | FileCheck -check-prefix DECLS-LOOKUPS %s
4 // RUN: %clang_cc1 -std=c++11 -DPRAGMA -fsyntax-only -verify %s 2>&1 | FileCheck -check-prefix PRAGMA %s
5 
6 namespace Test {
7   typedef int T;
8   extern int a;
9   int a = 0;
10 }
11 
12 #ifdef PRAGMA
13 #pragma clang __debug dump Test
14 // PRAGMA: lookup results for Test:
15 // PRAGMA-NEXT: NamespaceDecl {{.*}} Test
16 // PRAGMA-NEXT: |-TypedefDecl {{.*}} T 'int'
17 // PRAGMA-NEXT: | `-BuiltinType {{.*}} 'int'
18 // PRAGMA-NEXT: |-VarDecl [[EXTERN_A:0x[^ ]*]] {{.*}} a 'int' extern
19 // PRAGMA-NEXT: `-VarDecl {{.*}} prev [[EXTERN_A]] {{.*}} a 'int' cinit
20 // PRAGMA-NEXT:   `-IntegerLiteral {{.*}} 'int' 0
21 #endif
22 
23 namespace Test { }
24 
25 // DECLS: Dumping Test:
26 // DECLS-NEXT: NamespaceDecl {{.*}} Test
27 // DECLS-NEXT: |-TypedefDecl {{.*}} T 'int'
28 // DECLS-NEXT: | `-BuiltinType {{.*}} 'int'
29 // DECLS-NEXT: |-VarDecl [[EXTERN_A:0x[^ ]*]] {{.*}} a 'int' extern
30 // DECLS-NEXT: `-VarDecl {{.*}} prev [[EXTERN_A]] {{.*}} a 'int' cinit
31 // DECLS-NEXT:   `-IntegerLiteral {{.*}} 'int' 0
32 //
33 // DECLS: Dumping Test:
34 // DECLS-NEXT: NamespaceDecl {{.*}} Test
35 
36 // LOOKUPS: Dumping Test:
37 // LOOKUPS-NEXT: StoredDeclsMap Namespace {{.*}} 'Test'
38 // LOOKUPS:      DeclarationName 'a'
39 // LOOKUPS-NEXT: `-Var {{.*}} 'a' 'int'
40 //
41 // LOOKUPS: Dumping Test:
42 // LOOKUPS-NEXT: Lookup map is in primary DeclContext
43 
44 // DECLS-LOOKUPS: Dumping Test:
45 // DECLS-LOOKUPS-NEXT: StoredDeclsMap Namespace {{.*}} 'Test'
46 // DECLS-LOOKUPS:       -DeclarationName 'a'
47 // DECLS-LOOKUPS-NEXT:   `-Var [[A:[^ ]*]] 'a' 'int'
48 // DECLS-LOOKUPS-NEXT:     |-VarDecl [[EXTERN_A:0x[^ ]*]] {{.*}} a 'int' extern
49 // DECLS-LOOKUPS-NEXT:     `-VarDecl [[A]] prev [[EXTERN_A]] {{.*}} a 'int' cinit
50 // DECLS-LOOKUPS-NEXT:       `-IntegerLiteral {{.*}} 'int' 0
51 //
52 // DECLS-LOOKUPS: Dumping Test:
53 // DECLS-LOOKUPS-NEXT: Lookup map is in primary DeclContext
54 
55 #ifdef PRAGMA
56 namespace Test {
57   struct S {
operator +Test::S58     const S& operator+(const S&) { return *this; }
59   };
foo(S)60   void foo(S) {}
61 }
62 
63 #pragma clang __debug dump foo(Test::S{})
64 // PRAGMA: CallExpr {{.*}} adl
65 // PRAGMA-NEXT: |-ImplicitCastExpr {{.*}}
66 // PRAGMA-NEXT: | `-DeclRefExpr {{.*}} 'void (S)' lvalue Function {{.*}} 'foo' 'void (S)'
67 
68 #pragma clang __debug dump Test::S{} + Test::S{}
69 // PRAGMA: CXXOperatorCallExpr {{.*}}
70 // PRAGMA-NEXT: |-ImplicitCastExpr {{.*}}
71 // PRAGMA-NEXT: | `-DeclRefExpr {{.*}} 'const S &(const S &)' lvalue CXXMethod {{.*}} 'operator+' 'const S &(const S &)'
72 
73 #pragma clang __debug dump &Test::S::operator+
74 // PRAGMA: UnaryOperator {{.*}}
75 // PRAGMA-NEXT: `-DeclRefExpr {{.*}} 'const S &(const S &)' CXXMethod {{.*}} 'operator+' 'const S &(const S &)'
76 
77 template<typename T, int I>
bar()78 void bar() {
79 #pragma clang __debug dump T{} // expected-warning {{type-dependent expression}}
80 #pragma clang __debug dump +I  // expected-warning {{value-dependent expression}}
81 }
82 
83 template <typename T>
84 struct S {
85   static constexpr const T *str = "string";
86 };
87 
88 template <>
89 struct S<wchar_t> {
90   static constexpr const wchar_t *str = L"wide string";
91 };
92 
func()93 void func() {
94   #pragma clang __debug dump S<wchar_t>::str;
95   // PRAGMA: DeclRefExpr {{.*}} 'const wchar_t *const' lvalue Var {{.*}} 'str' 'const wchar_t *const'
96 }
97 
98 #pragma clang __debug dump this is nonsense // expected-error {{invalid use of 'this'}}
99 
100 #endif
101