diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1f138d247ff5..003930c7bd7a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1805,8 +1805,6 @@ def err_attribute_argument_n_not_identifier : Error< "'%0' attribute requires parameter %1 to be an identifier">; def err_attribute_argument_out_of_bounds : Error< "'%0' attribute parameter %1 is out of bounds">; -def err_attribute_requires_objc_interface : Error< - "attribute may only be applied to an Objective-C interface">; def err_attribute_uuid_malformed_guid : Error< "uuid attribute contains a malformed GUID">; def warn_nonnull_pointers_only : Warning< @@ -2006,7 +2004,7 @@ def warn_attribute_wrong_decl_type : Warning< "variables, functions and labels|fields and global variables|structs|" "variables, functions and tag types|thread-local variables|" "variables and fields|variables, data members and tag types|" - "types and namespaces}1">, + "types and namespaces|Objective-C interfaces}1">, InGroup; def err_attribute_wrong_decl_type : Error< "%0 attribute only applies to %select{functions|unions|" @@ -2016,7 +2014,7 @@ def err_attribute_wrong_decl_type : Error< "variables, functions and labels|fields and global variables|structs|" "variables, functions and tag types|thread-local variables|" "variables and fields|variables, data members and tag types|" - "types and namespaces}1">; + "types and namespaces|Objective-C interfaces}1">; def warn_function_attribute_wrong_type : Warning< "'%0' only applies to function types; type here is %1">, InGroup; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index cdc9649d9ad6..9d73ca3e48db 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -52,7 +52,8 @@ enum AttributeDeclKind { ExpectedTLSVar, ExpectedVariableOrField, ExpectedVariableFieldOrTag, - ExpectedTypeOrNamespace + ExpectedTypeOrNamespace, + ExpectedObjectiveCInterface }; //===----------------------------------------------------------------------===// @@ -2078,7 +2079,8 @@ static void handleArcWeakrefUnavailableAttr(Sema &S, Decl *D, static void handleObjCRootClassAttr(Sema &S, Decl *D, const AttributeList &Attr) { if (!isa(D)) { - S.Diag(Attr.getLoc(), diag::err_attribute_requires_objc_interface); + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) + << Attr.getName() << ExpectedObjectiveCInterface; return; } @@ -2490,7 +2492,8 @@ static void handleObjCExceptionAttr(Sema &S, Decl *D, ObjCInterfaceDecl *OCI = dyn_cast(D); if (OCI == 0) { - S.Diag(Attr.getLoc(), diag::err_attribute_requires_objc_interface); + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) + << Attr.getName() << ExpectedObjectiveCInterface; return; } diff --git a/clang/test/SemaObjC/attr-objc-exception.m b/clang/test/SemaObjC/attr-objc-exception.m index b497271521e2..dd8ac573deed 100644 --- a/clang/test/SemaObjC/attr-objc-exception.m +++ b/clang/test/SemaObjC/attr-objc-exception.m @@ -8,9 +8,9 @@ __attribute__((__objc_exception__)) @end -__attribute__((__objc_exception__)) // expected-error {{attribute may only be applied to an Objective-C interface}} +__attribute__((__objc_exception__)) // expected-error {{'__objc_exception__' attribute only applies to Objective-C interfaces}} int X; -__attribute__((__objc_exception__)) // expected-error {{attribute may only be applied to an Objective-C interface}} +__attribute__((__objc_exception__)) // expected-error {{'__objc_exception__' attribute only applies to Objective-C interfaces}} void foo(); diff --git a/clang/test/SemaObjC/attr-root-class.m b/clang/test/SemaObjC/attr-root-class.m index 195cd663acda..4f4c8b6997ce 100644 --- a/clang/test/SemaObjC/attr-root-class.m +++ b/clang/test/SemaObjC/attr-root-class.m @@ -11,6 +11,6 @@ __attribute__((objc_root_class)) @implementation NonRootClass @end -__attribute__((objc_root_class)) static void nonClassDeclaration() // expected-error {{attribute may only be applied to an Objective-C interface}} +__attribute__((objc_root_class)) static void nonClassDeclaration() // expected-error {{'objc_root_class' attribute only applies to Objective-C interfaces}} { }