r176832 - Objective-C: When using super.prop, property should be
Fariborz Jahanian
fjahanian at apple.com
Mon Mar 11 15:26:33 PDT 2013
Author: fjahanian
Date: Mon Mar 11 17:26:33 2013
New Revision: 176832
URL: http://llvm.org/viewvc/llvm-project?rev=176832&view=rev
Log:
Objective-C: When using super.prop, property should be
looked up the current class's super class.
// rdar://13349296
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/Coverage/objc-language-features.inc
cfe/trunk/test/SemaObjC/super-property-notation.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=176832&r1=176831&r2=176832&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Mar 11 17:26:33 2013
@@ -1561,8 +1561,15 @@ ActOnClassPropertyRefExpr(IdentifierInfo
if (ObjCMethodDecl *CurMethod = tryCaptureObjCSelf(receiverNameLoc)) {
if (CurMethod->isInstanceMethod()) {
- QualType T =
- Context.getObjCInterfaceType(CurMethod->getClassInterface());
+ ObjCInterfaceDecl *Super =
+ CurMethod->getClassInterface()->getSuperClass();
+ if (!Super) {
+ // The current class does not have a superclass.
+ Diag(receiverNameLoc, diag::error_root_class_cannot_use_super)
+ << CurMethod->getClassInterface()->getIdentifier();
+ return ExprError();
+ }
+ QualType T = Context.getObjCInterfaceType(Super);
T = Context.getObjCObjectPointerType(T);
return HandleExprPropertyRefExpr(T->getAsObjCInterfacePointerType(),
Modified: cfe/trunk/test/Coverage/objc-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/objc-language-features.inc?rev=176832&r1=176831&r2=176832&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/objc-language-features.inc (original)
+++ cfe/trunk/test/Coverage/objc-language-features.inc Mon Mar 11 17:26:33 2013
@@ -9,6 +9,7 @@
@class B;
@interface Root
+ at property(readonly) int p0;
@end
@interface A : Root <P1> {
Modified: cfe/trunk/test/SemaObjC/super-property-notation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super-property-notation.m?rev=176832&r1=176831&r2=176832&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super-property-notation.m (original)
+++ cfe/trunk/test/SemaObjC/super-property-notation.m Mon Mar 11 17:26:33 2013
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s
@interface B
+(int) classGetter;
@@ -29,3 +28,25 @@ void f0() {
int l2 = [A classGetter2];
}
+// rdar://13349296
+__attribute__((objc_root_class)) @interface ClassBase
+ at property (nonatomic, retain) ClassBase * foo;
+ at end
+
+ at implementation ClassBase
+- (void) Meth:(ClassBase*)foo {
+ super.foo = foo; // expected-error {{'ClassBase' cannot use 'super' because it is a root class}}
+ [super setFoo:foo]; // expected-error {{'ClassBase' cannot use 'super' because it is a root class}}
+}
+ at end
+
+ at interface ClassDerived : ClassBase
+ at property (nonatomic, retain) ClassDerived * foo;
+ at end
+
+ at implementation ClassDerived
+- (void) Meth:(ClassBase*)foo {
+ super.foo = foo; // issues compile warning
+ [super setFoo:foo]; // works with no warning
+}
+ at end
More information about the cfe-commits
mailing list