blob: 6c1bfe405e8697d8682627b7f8ee7bf58f505c00 [file] [log] [blame]
Matthias Gehred293cbd2019-07-25 17:50:51 +00001// RUN: %clang_cc1 -verify -ast-dump %s | \
2// RUN: FileCheck --implicit-check-not OwnerAttr --implicit-check-not PointerAttr %s
3
4int [[gsl::Owner]] i;
5// expected-error@-1 {{'Owner' attribute cannot be applied to types}}
6void [[gsl::Owner]] f();
7// expected-error@-1 {{'Owner' attribute cannot be applied to types}}
8
9[[gsl::Owner]] void f();
10// expected-warning@-1 {{'Owner' attribute only applies to structs}}
11
12union [[gsl::Owner(int)]] Union{};
13// expected-warning@-1 {{'Owner' attribute only applies to structs}}
14
15struct S {
16};
17
18S [[gsl::Owner]] Instance;
19// expected-error@-1 {{'Owner' attribute cannot be applied to types}}
20
21class [[gsl::Owner(7)]] OwnerDerefNoType{};
22// expected-error@-1 {{expected a type}}
23
24class [[gsl::Pointer("int")]] PointerDerefNoType{};
25// expected-error@-1 {{expected a type}}
26
27class [[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
32
33class [[gsl::Owner(void)]] OwnerVoidDerefType{};
Gabor Horvath247a6032020-01-02 11:57:42 -080034// CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType
35// CHECK: OwnerAttr {{.*}} void
Matthias Gehred293cbd2019-07-25 17:50:51 +000036class [[gsl::Pointer(void)]] PointerVoidDerefType{};
Gabor Horvath247a6032020-01-02 11:57:42 -080037// CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType
38// CHECK: PointerAttr {{.*}} void
Matthias Gehred293cbd2019-07-25 17:50:51 +000039
40class [[gsl::Pointer(int)]] AddConflictLater{};
41// CHECK: CXXRecordDecl {{.*}} AddConflictLater
42// CHECK: PointerAttr {{.*}} int
43class [[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
48
49class [[gsl::Owner(int)]] AddConflictLater2{};
50// CHECK: CXXRecordDecl {{.*}} AddConflictLater2
51// CHECK: OwnerAttr {{.*}} int
52class [[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
57
58class [[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
62// CHECK: OwnerAttr
63
64class [[gsl::Owner(int &)]] ReferenceType{};
65// expected-error@-1 {{a reference type is an invalid argument to attribute 'Owner'}}
66
67class [[gsl::Pointer(int[])]] ArrayType{};
68// expected-error@-1 {{an array type is an invalid argument to attribute 'Pointer'}}
69
70class [[gsl::Owner]] OwnerMissingParameter{};
71// CHECK: CXXRecordDecl {{.*}} OwnerMissingParameter
72// CHECK: OwnerAttr
73
74class [[gsl::Pointer]] PointerMissingParameter{};
75// CHECK: CXXRecordDecl {{.*}} PointerMissingParameter
76// CHECK: PointerAttr
77
78class [[gsl::Owner()]] OwnerWithEmptyParameterList{};
79// CHECK: CXXRecordDecl {{.*}} OwnerWithEmptyParameterList
80// CHECK: OwnerAttr {{.*}}
81
82class [[gsl::Pointer()]] PointerWithEmptyParameterList{};
83// CHECK: CXXRecordDecl {{.*}} PointerWithEmptyParameterList
84// CHECK: PointerAttr {{.*}}
85
86struct [[gsl::Owner(int)]] AnOwner{};
87// CHECK: CXXRecordDecl {{.*}} AnOwner
88// CHECK: OwnerAttr {{.*}} int
89
90struct S;
91class [[gsl::Pointer(S)]] APointer{};
92// CHECK: CXXRecordDecl {{.*}} APointer
93// CHECK: PointerAttr {{.*}} S
94
95class [[gsl::Owner(int)]] [[gsl::Owner(int)]] DuplicateOwner{};
96// CHECK: CXXRecordDecl {{.*}} DuplicateOwner
97// CHECK: OwnerAttr {{.*}} int
98
99class [[gsl::Pointer(int)]] [[gsl::Pointer(int)]] DuplicatePointer{};
100// CHECK: CXXRecordDecl {{.*}} DuplicatePointer
101// CHECK: PointerAttr {{.*}} int
102
103class [[gsl::Owner(int)]] AddTheSameLater{};
104// CHECK: CXXRecordDecl {{.*}} AddTheSameLater
105// CHECK: OwnerAttr {{.*}} int
106
107class [[gsl::Owner(int)]] AddTheSameLater;
108// CHECK: CXXRecordDecl {{.*}} prev {{.*}} AddTheSameLater
109// CHECK: OwnerAttr {{.*}} int
Matthias Gehref64f4882019-09-06 08:56:30 +0000110
111template <class T>
112class [[gsl::Owner]] ForwardDeclared;
113// CHECK: ClassTemplateDecl {{.*}} ForwardDeclared
114// CHECK: OwnerAttr {{.*}}
115// CHECK: ClassTemplateSpecializationDecl {{.*}} ForwardDeclared
116// CHECK: TemplateArgument type 'int'
117// CHECK: OwnerAttr {{.*}}
118
119template <class T>
120class [[gsl::Owner]] ForwardDeclared {
121// CHECK: ClassTemplateDecl {{.*}} ForwardDeclared
122// CHECK: CXXRecordDecl {{.*}} ForwardDeclared definition
123// CHECK: OwnerAttr {{.*}}
124};
125
126static_assert(sizeof(ForwardDeclared<int>), ""); // Force instantiation.