[cfe-commits] r146998 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/err-ivar-access-in-class-method.m

Fariborz Jahanian fjahanian at apple.com
Tue Dec 20 14:21:09 PST 2011


Author: fjahanian
Date: Tue Dec 20 16:21:08 2011
New Revision: 146998

URL: http://llvm.org/viewvc/llvm-project?rev=146998&view=rev
Log:
objc/c++: Issue diagnostic when free-standing ivar is accessed 
in class method instead of crash. // rdar://10593227

Added:
    cfe/trunk/test/SemaObjC/err-ivar-access-in-class-method.m
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=146998&r1=146997&r2=146998&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 20 16:21:08 2011
@@ -2010,6 +2010,12 @@
           Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
       }
     }
+  } else if (Lookup.isSingleResult() &&
+             Lookup.getFoundDecl()->isDefinedOutsideFunctionOrMethod()) {
+    // If accessing a stand-alone ivar in a class method, this is an error.
+    if (const ObjCIvarDecl *IV = dyn_cast<ObjCIvarDecl>(Lookup.getFoundDecl()))
+      return ExprError(Diag(Loc, diag::error_ivar_use_in_class_method)
+                       << IV->getDeclName());
   }
 
   if (Lookup.empty() && II && AllowBuiltinCreation) {

Added: cfe/trunk/test/SemaObjC/err-ivar-access-in-class-method.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/err-ivar-access-in-class-method.m?rev=146998&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/err-ivar-access-in-class-method.m (added)
+++ cfe/trunk/test/SemaObjC/err-ivar-access-in-class-method.m Tue Dec 20 16:21:08 2011
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s
+// rdar://10593227
+
+ at class UIWindow;
+
+ at interface CNAppDelegate
+
+ at property (strong, nonatomic) UIWindow *window;
+
+ at end
+
+
+ at interface CNAppDelegate ()
+ at property (nonatomic,retain) id foo;
+ at end
+
+ at implementation CNAppDelegate
+ at synthesize foo;
+ at synthesize window = _window;
+
++(void)myClassMethod;
+{
+        foo = 0; // expected-error {{instance variable 'foo' accessed in class method}}
+}
+ at end





More information about the cfe-commits mailing list