]> granicus.if.org Git - clang/commitdiff
objc: warn if NSObject attribute appears other than in a typedef.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 29 Nov 2011 01:48:40 +0000 (01:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 29 Nov 2011 01:48:40 +0000 (01:48 +0000)
// rdar://10453342

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145358 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/nsobject-attribute.m

index 38a7c19a35a85a866c66f8805e59efed22cab5b8..8a2313423d90e58c210ca5ce3c17029dc992d8d1 100644 (file)
@@ -181,6 +181,7 @@ def Unicode  : DiagGroup<"unicode">;
 def Uninitialized  : DiagGroup<"uninitialized">;
 def UninitializedMaybe : DiagGroup<"conditional-uninitialized">;
 def UnknownPragmas : DiagGroup<"unknown-pragmas">;
+def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
 def UnknownAttributes : DiagGroup<"attributes">;
 def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args",
                                         [CXX98CompatUnnamedTypeTemplateArgs]>;
index f566e10894e552cbef9f9afebcabdc5a2ec9d0a4..8bf377f8d0d65f12bdef782908d2f5cac2009447 100644 (file)
@@ -1348,10 +1348,9 @@ def warn_cxx98_compat_unicode_type : Warning<
 // Objective-C++
 def err_objc_decls_may_only_appear_in_global_scope : Error<
   "Objective-C declarations may only appear in global scope">;
+// Attributes
 def err_nsobject_attribute : Error<
   "__attribute ((NSObject)) is for pointer types only">;
-
-// Attributes
 def err_attribute_can_be_applied_only_to_symbol_declaration : Error<
   "%0 attribute can be applied only to symbol declaration">;
 def err_attributes_are_not_compatible : Error<
@@ -1463,6 +1462,9 @@ def warn_attribute_weak_on_field : Warning<
   "__weak attribute cannot be specified on a field declaration">;
 def warn_gc_attribute_weak_on_local : Warning<
   "Objective-C GC does not allow weak variables on the stack">;
+def warn_nsobject_attribute : Warning<
+  "__attribute ((NSObject)) may be put on a typedef only, "
+  "attribute is ignored">, InGroup<NSobjectAttribute>;
 def warn_attribute_weak_on_local : Warning<
   "__weak attribute cannot be specified on an automatic variable">;
 def warn_weak_identifier_undeclared : Warning<
index 74d22e7efee449ad601ffbace4ea36f72d60f605..e60cd633695143dcc14a976e27e5d7f8d3d73db1 100644 (file)
@@ -1746,6 +1746,10 @@ static void handleObjCNSObject(Sema &S, Decl *D, const AttributeList &Attr) {
       return;
     }
   }
+  else {
+    S.Diag(D->getLocation(), diag::warn_nsobject_attribute);
+    return;
+  }
   D->addAttr(::new (S.Context) ObjCNSObjectAttr(Attr.getRange(), S.Context));
 }
 
index 13a4929995bb6e6b063784e8eb4cbde7ae56057a..99f332de0ab62b660865471fe26cf5ea9eca9dc2 100644 (file)
@@ -15,8 +15,8 @@ typedef void *  __attribute__ ((NSObject)) CGColorRef2; // expected-error {{__at
 
 @property(copy) CGColorRef x;
 // rdar: // 7809460
-typedef struct CGColor *CGColorRefNoNSObject;
-@property (nonatomic, retain) __attribute__((NSObject)) CGColorRefNoNSObject color;
+typedef struct CGColor * __attribute__((NSObject)) CGColorRefNoNSObject;
+@property (nonatomic, retain) CGColorRefNoNSObject color;
 @end
 
 void setProperty(id self, id value)  {
@@ -40,3 +40,15 @@ int main(int argc, char *argv[]) {
     return 0;
 }
 
+// rdar://10453342
+@interface I
+{
+   __attribute__((NSObject)) void * color; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}}
+}
+@property (nonatomic, retain) __attribute__((NSObject)) void * color; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}} \
+                                // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
+@end
+void test_10453342() {
+    char* __attribute__((NSObject)) string2 = 0; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}}
+}
+