From 0337f21c78bdadff64bc6ae40eb9962d947e5bb0 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 7 Jul 2009 18:50:52 +0000 Subject: [PATCH] Diagnose, and not crash, when taking address of property expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74935 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 5 +++++ test/SemaObjC/property-expression-error.m | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/SemaObjC/property-expression-error.m diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d6e07bb6b3..97aae8b967 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4678,6 +4678,11 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { Diag(OpLoc, diag::err_typecheck_address_of) << "vector element" << op->getSourceRange(); return QualType(); + } else if (isa(op)) { + // cannot take address of a property expression. + Diag(OpLoc, diag::err_typecheck_address_of) + << "property expression" << op->getSourceRange(); + return QualType(); } else if (dcl) { // C99 6.5.3.2p1 // We have an lvalue with a decl. Make sure the decl is not declared // with the register storage-class specifier. diff --git a/test/SemaObjC/property-expression-error.m b/test/SemaObjC/property-expression-error.m new file mode 100644 index 0000000000..b648ee939d --- /dev/null +++ b/test/SemaObjC/property-expression-error.m @@ -0,0 +1,18 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +@interface AddressMyProperties +{ + unsigned index; +} +@property unsigned index; +@end + +@implementation AddressMyProperties +@synthesize index; +@end + +int main() { + AddressMyProperties *object; + &object.index; // expected-error {{address of property expression requested}} + return 0; +} -- 2.40.0