Diagnose attempts to qualify the name of an instance variable or

property in an Objective-C++ member access expression. Fixes PR9759.

llvm-svn: 141522
This commit is contained in:
Douglas Gregor 2011-10-09 23:22:49 +00:00
parent f7b98957ac
commit 12340e5b18
3 changed files with 32 additions and 1 deletions

View File

@ -3472,7 +3472,9 @@ def error_nosetter_property_assignment : Error<
"setter method is needed to assign to object using property" " assignment syntax">;
def error_no_subobject_property_setting : Error<
"expression is not assignable">;
def err_qualified_objc_access : Error<
"%select{property|ivar}0 access cannot be qualified with '%1'">;
def ext_freestanding_complex : Extension<
"complex numbers are an extension in a freestanding C99 implementation">;

View File

@ -1045,6 +1045,13 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
// Handle ivar access to Objective-C objects.
if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) {
if (!SS.isEmpty()) {
Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
<< 1 << SS.getScopeRep()
<< FixItHint::CreateRemoval(SS.getRange());
SS.clear();
}
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
// There are three cases for the base type:
@ -1163,6 +1170,13 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
// Objective-C property access.
const ObjCObjectPointerType *OPT;
if (!IsArrow && (OPT = BaseType->getAs<ObjCObjectPointerType>())) {
if (!SS.isEmpty()) {
Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
<< 0 << SS.getScopeRep()
<< FixItHint::CreateRemoval(SS.getRange());
SS.clear();
}
// This actually uses the base as an r-value.
BaseExpr = DefaultLvalueConversion(BaseExpr.take());
if (BaseExpr.isInvalid())

View File

@ -50,3 +50,18 @@ void g(B *b) {
b->operator+ = 17; // expected-error{{'B' does not have a member named 'operator+'}}
}
@end
// PR9759
class Forward;
@interface D {
@public
int ivar;
}
@property int property;
@end
void testD(D *d) {
d.Forward::property = 17; // expected-error{{property access cannot be qualified with 'Forward::'}}
d->Forward::ivar = 12; // expected-error{{ivar access cannot be qualified with 'Forward::'}}
}