diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2014-05-28 18:12:10 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2014-05-28 18:12:10 +0000 |
commit | 4290e78b6bdf96750bf0b1aa084a912a2e03909b (patch) | |
tree | d955a7d346e454c188402568ed2fc5aee30c3d57 /lib/Sema/SemaPseudoObject.cpp | |
parent | db4dfb634e7f345b74766b3d6743b7277d2613ab (diff) | |
download | clang-4290e78b6bdf96750bf0b1aa084a912a2e03909b.tar.gz |
Objective-C. Diagnose use of properties in functions nested in,
now deprecated, ObjC containers instead of crashing.
// rdar://16859666
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209758 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaPseudoObject.cpp')
-rw-r--r-- | lib/Sema/SemaPseudoObject.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 94b19431a3..339fe07b8c 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -284,6 +284,7 @@ namespace { bool tryBuildGetOfReference(Expr *op, ExprResult &result); bool findSetter(bool warn=true); bool findGetter(); + bool DiagnoseUnsupportedPropertyUse(); Expr *rebuildAndCaptureObject(Expr *syntacticBase) override; ExprResult buildGet() override; @@ -643,6 +644,20 @@ bool ObjCPropertyOpBuilder::findSetter(bool warn) { return false; } +bool ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() { + if (S.getCurLexicalContext()->isObjCContainer() && + S.getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl && + S.getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) { + if (ObjCPropertyDecl *prop = RefExpr->getExplicitProperty()) { + S.Diag(RefExpr->getLocation(), + diag::err_property_function_in_objc_container); + S.Diag(prop->getLocation(), diag::note_property_declare); + return true; + } + } + return false; +} + /// Capture the base object of an Objective-C property expression. Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) { assert(InstanceReceiver == nullptr); @@ -666,6 +681,9 @@ Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) { /// Load from an Objective-C property reference. ExprResult ObjCPropertyOpBuilder::buildGet() { findGetter(); + if (!Getter && DiagnoseUnsupportedPropertyUse()) + return ExprError(); + assert(Getter); if (SyntacticRefExpr) @@ -704,6 +722,8 @@ ExprResult ObjCPropertyOpBuilder::buildGet() { ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc, bool captureSetValueAsResult) { bool hasSetter = findSetter(false); + if (!hasSetter && DiagnoseUnsupportedPropertyUse()) + return ExprError(); assert(hasSetter); (void) hasSetter; if (SyntacticRefExpr) |