]> granicus.if.org Git - clang/commitdiff
Add requirement that attribute 'objc_protocol_requires_explicit_implementation' can...
authorTed Kremenek <kremenek@apple.com>
Fri, 21 Feb 2014 22:49:04 +0000 (22:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 21 Feb 2014 22:49:04 +0000 (22:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201899 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/protocols-suppress-conformance.m

index 62ae84595cb5a40170159a2f59ee290f5b45871b..aaebf59d8aa148f9400f46d0a5fca636dcfb6e38 100644 (file)
@@ -2499,7 +2499,10 @@ def err_objc_bridged_related_invalid_class_name : Error<
 def err_objc_bridged_related_known_method : Error<
  "%0 must be explicitly converted to %1; use %select{%objcclass2|%objcinstance2}3 "
  "method for this conversion">;
-  
+
+def err_objc_attr_protocol_requires_definition : Error<
+  "attribute %0 can only be applied to @protocol definitions, not forward declarations">;
+
 // Function Parameter Semantic Analysis.
 def err_param_with_void_type : Error<"argument may not have 'void' type">;
 def err_void_only_param : Error<
index 19b79555489e59b7c337b1df93d005ba140c29d8..88cdc756ec16f575b9b04fdc4cb5b37623ea8ed5 100644 (file)
@@ -1643,8 +1643,14 @@ static void handleAttrWithMessage(Sema &S, Decl *D,
                                       Attr.getAttributeSpellingListIndex()));
 }
 
-static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D,
+static void handleObjCSuppresProtocolAttr(Sema &S, ObjCProtocolDecl *D,
                                           const AttributeList &Attr) {
+  if (!D->isThisDeclarationADefinition()) {
+    S.Diag(Attr.getLoc(), diag::err_objc_attr_protocol_requires_definition)
+      << Attr.getName() << Attr.getRange();
+    return;
+  }
+
   D->addAttr(::new (S.Context)
           ObjCExplicitProtocolImplAttr(Attr.getRange(), S.Context,
                                        Attr.getAttributeSpellingListIndex()));
@@ -4191,7 +4197,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
   case AttributeList::AT_ObjCRootClass:
     handleSimpleAttribute<ObjCRootClassAttr>(S, D, Attr); break;
   case AttributeList::AT_ObjCExplicitProtocolImpl:
-    handleObjCSuppresProtocolAttr(S, D, Attr);
+    handleObjCSuppresProtocolAttr(S, cast<ObjCProtocolDecl>(D), Attr);
     break;
   case AttributeList::AT_ObjCRequiresPropertyDefs:
     handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, Attr); break;
index 05c0486181f3f9f48b7c1877ae65c9883b29c9ed..406c9132a8bf41d79fda86645b9edcfc83d5e02f 100644 (file)
@@ -141,3 +141,6 @@ __attribute__((objc_protocol_requires_explicit_implementation))
 - (void)dunwich {}
 @end
 
+__attribute__((objc_protocol_requires_explicit_implementation))  // expected-error{{attribute 'objc_protocol_requires_explicit_implementation' can only be applied to @protocol definitions, not forward declarations}}
+@protocol NotDefined;
+