]> granicus.if.org Git - clang/commitdiff
Type of property and its ivar is more restrictive
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 19 Jan 2009 20:13:47 +0000 (20:13 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 19 Jan 2009 20:13:47 +0000 (20:13 +0000)
that rules for assignment.

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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/property-ivar-mismatch.m [new file with mode: 0644]

index d140b908a800b12615d0fd9766d91bed32630caf..c4fccc7671aa76523cf12db1a94269799ef84b20 100644 (file)
@@ -1698,6 +1698,21 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
           << property->getDeclName() << Ivar->getDeclName();
         return 0;
       }
+      else {
+        // FIXME! Rules for properties are somewhat different that those
+        // for assignments. Use a new routine to consolidate all cases;
+        // specifically for property redeclarations as well as for ivars.
+        QualType lhsType = 
+                    Context.getCanonicalType(PropType).getUnqualifiedType();
+        QualType rhsType = 
+                    Context.getCanonicalType(IvarType).getUnqualifiedType();
+        if (lhsType != rhsType && 
+            lhsType->isArithmeticType()) {
+          Diag(PropertyLoc, diag::error_property_ivar_type)
+          << property->getDeclName() << Ivar->getDeclName();
+          return 0;
+        }
+      }
     }
   } else if (PropertyIvar) {
     // @dynamic
diff --git a/test/SemaObjC/property-ivar-mismatch.m b/test/SemaObjC/property-ivar-mismatch.m
new file mode 100644 (file)
index 0000000..a0bc929
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: clang -fsyntax-only -verify %s
+// Test that arithmatic types on property and its ivar have exact match.
+
+@interface Test4 
+{
+   char ivar;
+}
+@property int prop;
+@end
+
+@implementation Test4
+@synthesize prop = ivar;  // expected-error {{type of property 'prop' does not match type of ivar 'ivar'}}
+@end
+