brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 4c33d5c Raw
127 lines · cpp
1// RUN: %clang_cc1 -verify -ast-dump %s | \2// RUN: FileCheck --implicit-check-not OwnerAttr --implicit-check-not PointerAttr %s3 4int [[gsl::Owner]] i;5// expected-error@-1 {{'gsl::Owner' attribute cannot be applied to types}}6void [[gsl::Owner]] f();7// expected-error@-1 {{'gsl::Owner' attribute cannot be applied to types}}8 9[[gsl::Owner]] void f();10// expected-warning@-1 {{'gsl::Owner' attribute only applies to structs}}11 12union [[gsl::Owner(int)]] Union{};13// expected-warning@-1 {{'gsl::Owner' attribute only applies to structs}}14 15struct S {16};17 18S [[gsl::Owner]] Instance;19// expected-error@-1 {{'gsl::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 {{'gsl::Pointer' and 'gsl::Owner' attributes are not compatible}}29// expected-note@-2 {{conflicting attribute is here}}30// CHECK: CXXRecordDecl {{.*}} BothOwnerPointer31// CHECK: OwnerAttr {{.*}} int32 33class [[gsl::Owner(void)]] OwnerVoidDerefType{};34// CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType35// CHECK: OwnerAttr {{.*}} void36class [[gsl::Pointer(void)]] PointerVoidDerefType{};37// CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType38// CHECK: PointerAttr {{.*}} void39 40class [[gsl::Pointer(int)]] AddConflictLater{};41// CHECK: CXXRecordDecl {{.*}} AddConflictLater42// CHECK: PointerAttr {{.*}} int43class [[gsl::Owner(int)]] AddConflictLater;44// expected-error@-1 {{'gsl::Owner' and 'gsl::Pointer' attributes are not compatible}}45// expected-note@-5 {{conflicting attribute is here}}46// CHECK: CXXRecordDecl {{.*}} AddConflictLater47// CHECK: PointerAttr {{.*}} Inherited int48 49class [[gsl::Owner(int)]] AddConflictLater2{};50// CHECK: CXXRecordDecl {{.*}} AddConflictLater251// CHECK: OwnerAttr {{.*}} int52class [[gsl::Owner(float)]] AddConflictLater2;53// expected-error@-1 {{'gsl::Owner' and 'gsl::Owner' attributes are not compatible}}54// expected-note@-5 {{conflicting attribute is here}}55// CHECK: CXXRecordDecl {{.*}} AddConflictLater56// CHECK: OwnerAttr {{.*}} Inherited int57 58class [[gsl::Owner()]] [[gsl::Owner(int)]] WithAndWithoutParameter{};59// expected-error@-1 {{'gsl::Owner' and 'gsl::Owner' attributes are not compatible}}60// expected-note@-2 {{conflicting attribute is here}}61// CHECK: CXXRecordDecl {{.*}} WithAndWithoutParameter62// CHECK: OwnerAttr63 64class [[gsl::Owner(int &)]] ReferenceType{};65// expected-error@-1 {{a reference type is an invalid argument to attribute 'gsl::Owner'}}66 67class [[gsl::Pointer(int[])]] ArrayType{};68// expected-error@-1 {{an array type is an invalid argument to attribute 'gsl::Pointer'}}69 70class [[gsl::Owner]] OwnerMissingParameter{};71// CHECK: CXXRecordDecl {{.*}} OwnerMissingParameter72// CHECK: OwnerAttr73 74class [[gsl::Pointer]] PointerMissingParameter{};75// CHECK: CXXRecordDecl {{.*}} PointerMissingParameter76// CHECK: PointerAttr77 78class [[gsl::Owner()]] OwnerWithEmptyParameterList{};79// CHECK: CXXRecordDecl {{.*}} OwnerWithEmptyParameterList80// CHECK: OwnerAttr {{.*}}81 82class [[gsl::Pointer()]] PointerWithEmptyParameterList{};83// CHECK: CXXRecordDecl {{.*}} PointerWithEmptyParameterList84// CHECK: PointerAttr {{.*}}85 86struct [[gsl::Owner(int)]] AnOwner{};87// CHECK: CXXRecordDecl {{.*}} AnOwner88// CHECK: OwnerAttr {{.*}} int89 90struct S;91class [[gsl::Pointer(S)]] APointer{};92// CHECK: CXXRecordDecl {{.*}} APointer93// CHECK: PointerAttr {{.*}} S94 95class [[gsl::Owner(int)]] [[gsl::Owner(int)]] DuplicateOwner{};96// CHECK: CXXRecordDecl {{.*}} DuplicateOwner97// CHECK: OwnerAttr {{.*}} int98 99class [[gsl::Pointer(int)]] [[gsl::Pointer(int)]] DuplicatePointer{};100// CHECK: CXXRecordDecl {{.*}} DuplicatePointer101// CHECK: PointerAttr {{.*}} int102 103class [[gsl::Owner(int)]] AddTheSameLater{};104// CHECK: CXXRecordDecl {{.*}} AddTheSameLater105// CHECK: OwnerAttr {{.*}} int106 107class [[gsl::Owner(int)]] AddTheSameLater;108// CHECK: CXXRecordDecl {{.*}} prev {{.*}} AddTheSameLater109// CHECK: OwnerAttr {{.*}} int110 111template <class T>112class [[gsl::Owner]] ForwardDeclared;113// CHECK: ClassTemplateDecl {{.*}} ForwardDeclared114// CHECK: OwnerAttr {{.*}}115// CHECK: ClassTemplateSpecializationDecl {{.*}} ForwardDeclared116// CHECK: TemplateArgument type 'int'117// CHECK: OwnerAttr {{.*}}118 119template <class T>120class [[gsl::Owner]] ForwardDeclared {121// CHECK: ClassTemplateDecl {{.*}} ForwardDeclared122// CHECK: CXXRecordDecl {{.*}} ForwardDeclared definition123// CHECK: OwnerAttr {{.*}}124};125 126static_assert(sizeof(ForwardDeclared<int>), ""); // Force instantiation.127