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