]> granicus.if.org Git - clang/commitdiff
In objc2's None-Fragile ABI, one cannot use the super class ivar for
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 13 Apr 2009 19:30:37 +0000 (19:30 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 13 Apr 2009 19:30:37 +0000 (19:30 +0000)
setter/getter synthesis.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/ivar-sem-check-2.m [new file with mode: 0644]

index 56a9fa9ac3e7abd803efb4c389f05713790f7cb2..c629a82a2cdc27eb6036b104c2238b629f4efd92 100644 (file)
@@ -212,6 +212,8 @@ def error_synthesized_ivar_yet_not_supported : Error<
 
 def error_property_ivar_type : Error<
   "type of property %0 does not match type of ivar %1">;
+def error_ivar_in_superclass_use : Error<
+  "property %0 attempting to use ivar %1 declared in in super class %2">;
 def error_weak_property : Error<
   "existing ivar %1 for __weak property %0 must be __weak">;
 def error_strong_property : Error<
index cf782caf5c0b6c339bec358ea52e27cb3488877c..d468c1334eabf47a57a46025dfd07f015d302b86 100644 (file)
@@ -1791,11 +1791,13 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
   // Check that we have a valid, previously declared ivar for @synthesize
   if (Synthesize) {
     // @synthesize
+    bool NoExplicitPropertyIvar = (!PropertyIvar);
     if (!PropertyIvar)
       PropertyIvar = PropertyId;
     QualType PropType = Context.getCanonicalType(property->getType());
     // Check that this is a previously declared 'ivar' in 'IDecl' interface
-    Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar);
+    ObjCInterfaceDecl *ClassDeclared;
+    Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar, ClassDeclared);
     if (!Ivar) {
       if (getLangOptions().ObjCNonFragileABI) {
         Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc, 
@@ -1809,6 +1811,15 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
         return DeclPtrTy();
       }
     }
+    else if (getLangOptions().ObjCNonFragileABI &&
+             NoExplicitPropertyIvar && ClassDeclared != IDecl) {
+      Diag(PropertyLoc, diag::error_ivar_in_superclass_use)
+        << property->getDeclName() << Ivar->getDeclName() 
+        << ClassDeclared->getDeclName();
+      Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
+        << Ivar << Ivar->getNameAsCString();
+      // Note! I deliberately want it to fall thru so more errors are caught.
+    }
     QualType IvarType = Context.getCanonicalType(Ivar->getType());
     
     // Check that type of property and its ivar are type compatible.
diff --git a/test/SemaObjC/ivar-sem-check-2.m b/test/SemaObjC/ivar-sem-check-2.m
new file mode 100644 (file)
index 0000000..2b85685
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: clang-cc  -fsyntax-only -triple x86_64-apple-darwin10 -verify %s
+
+@interface Super  {
+  id value; // expected-note {{previously declared 'value' here}}
+} 
+@property(retain) id value;
+@property(retain) id value1;
+@end
+
+@interface Sub : Super @end
+
+@implementation Sub
+@synthesize value; // expected-error {{property 'value' attempting to use ivar 'value' declared in in super class 'Super'}} // expected-note {{previous use is here}}
+@synthesize value1=value; // expected-error {{synthesized properties 'value1' and 'value' both claim ivar 'value'}}
+@end
+
+