From 5d36ac2cc91125134fd8e1f0a0f1c2f888fb0566 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 12 May 2009 21:36:23 +0000 Subject: [PATCH] Method attributes may only be specified on method declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71597 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaDeclObjC.cpp | 4 ++++ test/SemaObjC/attr-deprecated.m | 2 +- test/SemaObjC/method-attributes.m | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 4c7a11668f..65a25ce934 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1720,5 +1720,8 @@ def error_ivar_use_in_class_method : Error< def error_private_ivar_access : Error<"instance variable %0 is private">; def error_protected_ivar_access : Error<"instance variable %0 is protected">; def warn_maynot_respond : Warning<"%0 may not respond to %1">; +def warn_attribute_method_def : Warning< + "method attribute may be specified on method declarations only">; + } diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 76e73fc650..d854f0b50c 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1671,6 +1671,8 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( PrevMethod = ImpDecl->getClassMethod(Context, Sel); ImpDecl->addClassMethod(Context, ObjCMethod); } + if (AttrList) + Diag(EndLoc, diag::warn_attribute_method_def); } else if (ObjCCategoryImplDecl *CatImpDecl = dyn_cast(ClassDecl)) { @@ -1681,6 +1683,8 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( PrevMethod = CatImpDecl->getClassMethod(Context, Sel); CatImpDecl->addClassMethod(Context, ObjCMethod); } + if (AttrList) + Diag(EndLoc, diag::warn_attribute_method_def); } if (PrevMethod) { // You can never have two method definitions with the same name. diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index 52f654ab5d..3741510e11 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -9,7 +9,7 @@ @implementation A + (void)F __attribute__((deprecated)) -{ +{ // expected-warning {{method attribute may be specified on method declarations only}} [self F]; // no warning, since the caller is also deprecated. } diff --git a/test/SemaObjC/method-attributes.m b/test/SemaObjC/method-attributes.m index 003cea4bd7..354950c49c 100644 --- a/test/SemaObjC/method-attributes.m +++ b/test/SemaObjC/method-attributes.m @@ -8,3 +8,25 @@ -(void) m0 __attribute__((noreturn)); -(void) m1 __attribute__((unused)); @end + + +@interface INTF +- (int) foo1: (int)arg1 __attribute__((deprecated)); + +- (int) foo: (int)arg1; + +- (int) foo2: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)); +@end + +@implementation INTF +- (int) foo: (int)arg1 __attribute__((deprecated)){ // expected-warning {{method attribute may be specified}} + return 10; +} +- (int) foo1: (int)arg1 { + return 10; +} +- (int) foo2: (int)arg1 __attribute__((deprecated)) { // expected-warning {{method attribute may be specified}} + return 10; +} +@end + -- 2.40.0