1 // RUN: %clang_cc1 -verify -ast-dump %s | \
2 // RUN: FileCheck --implicit-check-not OwnerAttr --implicit-check-not PointerAttr %s
5 // expected-error@-1 {{'Owner' attribute cannot be applied to types}}
6 void [[gsl::Owner
]] f();
7 // expected-error@-1 {{'Owner' attribute cannot be applied to types}}
9 [[gsl::Owner
]] void f();
10 // expected-warning@-1 {{'Owner' attribute only applies to structs}}
12 union [[gsl::Owner(int)]] Union
{};
13 // expected-warning@-1 {{'Owner' attribute only applies to structs}}
18 S
[[gsl::Owner
]] Instance
;
19 // expected-error@-1 {{'Owner' attribute cannot be applied to types}}
21 class [[gsl::Owner(7)]] OwnerDerefNoType
{};
22 // expected-error@-1 {{expected a type}}
24 class [[gsl::Pointer("int")]] PointerDerefNoType
{};
25 // expected-error@-1 {{expected a type}}
27 class [[gsl::Owner(int)]] [[gsl::Pointer(int)]] BothOwnerPointer
{};
28 // expected-error@-1 {{'Pointer' and 'Owner' attributes are not compatible}}
29 // expected-note@-2 {{conflicting attribute is here}}
30 // CHECK: CXXRecordDecl {{.*}} BothOwnerPointer
31 // CHECK: OwnerAttr {{.*}} int
33 class [[gsl::Owner(void)]] OwnerVoidDerefType
{};
34 // CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType
35 // CHECK: OwnerAttr {{.*}} void
36 class [[gsl::Pointer(void)]] PointerVoidDerefType
{};
37 // CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType
38 // CHECK: PointerAttr {{.*}} void
40 class [[gsl::Pointer(int)]] AddConflictLater
{};
41 // CHECK: CXXRecordDecl {{.*}} AddConflictLater
42 // CHECK: PointerAttr {{.*}} int
43 class [[gsl::Owner(int)]] AddConflictLater
;
44 // expected-error@-1 {{'Owner' and 'Pointer' attributes are not compatible}}
45 // expected-note@-5 {{conflicting attribute is here}}
46 // CHECK: CXXRecordDecl {{.*}} AddConflictLater
47 // CHECK: PointerAttr {{.*}} Inherited int
49 class [[gsl::Owner(int)]] AddConflictLater2
{};
50 // CHECK: CXXRecordDecl {{.*}} AddConflictLater2
51 // CHECK: OwnerAttr {{.*}} int
52 class [[gsl::Owner(float)]] AddConflictLater2
;
53 // expected-error@-1 {{'Owner' and 'Owner' attributes are not compatible}}
54 // expected-note@-5 {{conflicting attribute is here}}
55 // CHECK: CXXRecordDecl {{.*}} AddConflictLater
56 // CHECK: OwnerAttr {{.*}} Inherited int
58 class [[gsl::Owner()]] [[gsl::Owner(int)]] WithAndWithoutParameter
{};
59 // expected-error@-1 {{'Owner' and 'Owner' attributes are not compatible}}
60 // expected-note@-2 {{conflicting attribute is here}}
61 // CHECK: CXXRecordDecl {{.*}} WithAndWithoutParameter
64 class [[gsl::Owner(int &)]] ReferenceType
{};
65 // expected-error@-1 {{a reference type is an invalid argument to attribute 'Owner'}}
67 class [[gsl::Pointer(int[])]] ArrayType
{};
68 // expected-error@-1 {{an array type is an invalid argument to attribute 'Pointer'}}
70 class [[gsl::Owner
]] OwnerMissingParameter
{};
71 // CHECK: CXXRecordDecl {{.*}} OwnerMissingParameter
74 class [[gsl::Pointer
]] PointerMissingParameter
{};
75 // CHECK: CXXRecordDecl {{.*}} PointerMissingParameter
78 class [[gsl::Owner()]] OwnerWithEmptyParameterList
{};
79 // CHECK: CXXRecordDecl {{.*}} OwnerWithEmptyParameterList
80 // CHECK: OwnerAttr {{.*}}
82 class [[gsl::Pointer()]] PointerWithEmptyParameterList
{};
83 // CHECK: CXXRecordDecl {{.*}} PointerWithEmptyParameterList
84 // CHECK: PointerAttr {{.*}}
86 struct [[gsl::Owner(int)]] AnOwner
{};
87 // CHECK: CXXRecordDecl {{.*}} AnOwner
88 // CHECK: OwnerAttr {{.*}} int
91 class [[gsl::Pointer(S
)]] APointer
{};
92 // CHECK: CXXRecordDecl {{.*}} APointer
93 // CHECK: PointerAttr {{.*}} S
95 class [[gsl::Owner(int)]] [[gsl::Owner(int)]] DuplicateOwner
{};
96 // CHECK: CXXRecordDecl {{.*}} DuplicateOwner
97 // CHECK: OwnerAttr {{.*}} int
99 class [[gsl::Pointer(int)]] [[gsl::Pointer(int)]] DuplicatePointer
{};
100 // CHECK: CXXRecordDecl {{.*}} DuplicatePointer
101 // CHECK: PointerAttr {{.*}} int
103 class [[gsl::Owner(int)]] AddTheSameLater
{};
104 // CHECK: CXXRecordDecl {{.*}} AddTheSameLater
105 // CHECK: OwnerAttr {{.*}} int
107 class [[gsl::Owner(int)]] AddTheSameLater
;
108 // CHECK: CXXRecordDecl {{.*}} prev {{.*}} AddTheSameLater
109 // CHECK: OwnerAttr {{.*}} int
112 class [[gsl::Owner
]] ForwardDeclared
;
113 // CHECK: ClassTemplateDecl {{.*}} ForwardDeclared
114 // CHECK: OwnerAttr {{.*}}
115 // CHECK: ClassTemplateSpecializationDecl {{.*}} ForwardDeclared
116 // CHECK: TemplateArgument type 'int'
117 // CHECK: OwnerAttr {{.*}}
120 class [[gsl::Owner
]] ForwardDeclared
{
121 // CHECK: ClassTemplateDecl {{.*}} ForwardDeclared
122 // CHECK: CXXRecordDecl {{.*}} ForwardDeclared definition
123 // CHECK: OwnerAttr {{.*}}
126 static_assert(sizeof(ForwardDeclared
<int>), ""); // Force instantiation.