Diagnose attempts to qualify the name of an instance variable or

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141522 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2011-10-09 23:22:49 +00:00
Родитель 6d0468b2d3
Коммит b5ae92f2f5
3 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -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">;

Просмотреть файл

@ -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())

Просмотреть файл

@ -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::'}}
}