1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fcxx-exceptions %s
2 // RUN: %clang_cc1 -fsyntax-only -ast-dump -ast-dump-filter test -std=c++11 -fcxx-exceptions %s | FileCheck %s
3 // expected-no-diagnostics
4
5 class testClass1 {
6 };
7 // CHECK-LABEL: CXXRecordDecl{{.*}} testClass1
8 // CHECK-NOT: AnnotateAttr
9
10 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to=any(record, field, variable, function, namespace, type_alias))
11
12 class testClass2 {
13 void testMethod1(int param);
14
15 testClass2();
16
17 testClass2 *operator -> ();
18 };
19 // CHECK-LABEL: CXXRecordDecl{{.*}} testClass2
20 // CHECK: AnnotateAttr{{.*}} "test"
21 // CHECK: CXXMethodDecl{{.*}} testMethod1
22 // CHECK-NEXT: ParmVarDecl{{.*}} param
23 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
24 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
25 // CHECK-NEXT: CXXConstructorDecl
26 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
27 // CHECK-NEXT: CXXMethodDecl{{.*}} operator->
28 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
29
30 #pragma clang attribute push (__attribute__((annotate("method"))), apply_to=any(record, field, variable, function, namespace, type_alias))
31
testMethod1(int param)32 void testClass2::testMethod1(int param) {
33
34 #pragma clang attribute pop
35 }
36 // CHECK-LABEL: CXXMethodDecl{{.*}}prev{{.*}} testMethod1
37 // CHECK-NEXT: ParmVarDecl{{.*}} param
38 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
39 // CHECK-NEXT: AnnotateAttr{{.*}} "method"
40 // CHECK-NEXT: CompoundStmt
41 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
42 // CHECK-NEXT: AnnotateAttr{{.*}} "method"
43
44 namespace testNamespace {
45 }
46 // CHECK-LABEL: NamespaceDecl{{.*}} testNamespace
47 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
48
49 class testClassForward;
50 // CHECK-LABEL: CXXRecordDecl{{.*}} testClassForward
51 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
52
53 namespace testNamespaceAlias = testNamespace;
54 // CHECK-LABEL: NamespaceAliasDecl{{.*}} testNamespaceAlias
55 // CHECK-NOT: AnnotateAttr
56
57 using testTypeAlias = testClass2;
58 // CHECK-LABEL: TypeAliasDecl{{.*}} testTypeAlias
59 // CHECK: AnnotateAttr{{.*}} "test"
60
testCatchVariable()61 void testCatchVariable() {
62 try {
63 } catch (int testCatch) {
64 }
65 testCatchVariable();
66 }
67 // CHECK-LABEL: FunctionDecl{{.*}} testCatchVariable
68 // CHECK: CXXCatchStmt
69 // CHECK-NEXT: VarDecl{{.*}} testCatch
70 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
71
testLambdaMethod()72 void testLambdaMethod() {
73 auto l = [] () { };
74 testLambdaMethod();
75 }
76 // CHECK-LABEL: FunctionDecl{{.*}} testLambdaMethod
77 // CHECK: LambdaExpr
78 // CHECK-NEXT: CXXRecordDecl
79 // CHECK: CXXMethodDecl{{.*}} operator()
80 // CHECK-NEXT: CompoundStmt
81 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
82
83 #pragma clang attribute pop
84
85 #pragma clang attribute push (__attribute__((require_constant_initialization)), apply_to=variable(is_global))
86
87 int testCI1 = 1;
88 // CHECK-LABEL: VarDecl{{.*}} testCI1
89 // CHECK-NEXT: IntegerLiteral
90 // CHECK-NEXT: ConstInitAttr
91
92 #pragma clang attribute pop
93
94 int testNoCI = 0;
95 // CHECK-LABEL: VarDecl{{.*}} testNoCI
96 // CHECK-NEXT: IntegerLiteral
97 // CHECK-NOT: ConstInitAttr
98
99 // Check support for CXX11 style attributes
100 #pragma clang attribute push ([[noreturn]], apply_to = function)
101
102 void testNoReturn();
103 // CHECK-LABEL: FunctionDecl{{.*}} testNoReturn
104 // CHECK-NEXT: CXX11NoReturnAttr
105
106 #pragma clang attribute pop
107