From 028b9e1d0a7d18be9763bb0285cf4a9b8c0b9e12 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 20 Dec 2011 22:21:08 +0000 Subject: objc/c++: Issue diagnostic when free-standing ivar is accessed in class method instead of crash. // rdar://10593227 llvm-svn: 146998 --- clang/lib/Sema/SemaExpr.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 62ee9f554d5..65439032f2c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2010,6 +2010,12 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S, 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(Lookup.getFoundDecl())) + return ExprError(Diag(Loc, diag::error_ivar_use_in_class_method) + << IV->getDeclName()); } if (Lookup.empty() && II && AllowBuiltinCreation) { -- cgit v1.2.3