Some refactoring of member access for

performace sake. Also added a test case.

llvm-svn: 77502
This commit is contained in:
Fariborz Jahanian
2009-07-29 20:41:46 +00:00
parent ee68a483ec
commit 4b12ed115a
2 changed files with 30 additions and 16 deletions

View File

@@ -1031,23 +1031,21 @@ Sema::PerformObjectMemberConversion(Expr *&From, NamedDecl *Member) {
dyn_cast<CXXRecordDecl>(FD->getDeclContext())) {
QualType DestType =
Context.getCanonicalType(Context.getTypeDeclType(RD));
if (!DestType->isDependentType() &&
!From->getType()->isDependentType()) {
QualType FromRecordType = From->getType();
QualType DestRecordType = DestType;
if (FromRecordType->getAsPointerType()) {
DestType = Context.getPointerType(DestType);
FromRecordType = FromRecordType->getPointeeType();
}
if (IsDerivedFrom(FromRecordType, DestRecordType) &&
CheckDerivedToBaseConversion(FromRecordType,
DestRecordType,
From->getSourceRange().getBegin(),
From->getSourceRange()))
return true;
ImpCastExprToType(From, DestType, /*isLvalue=*/true);
if (DestType->isDependentType() || From->getType()->isDependentType())
return false;
QualType FromRecordType = From->getType();
QualType DestRecordType = DestType;
if (FromRecordType->getAsPointerType()) {
DestType = Context.getPointerType(DestType);
FromRecordType = FromRecordType->getPointeeType();
}
if (!Context.hasSameUnqualifiedType(FromRecordType, DestRecordType) &&
CheckDerivedToBaseConversion(FromRecordType,
DestRecordType,
From->getSourceRange().getBegin(),
From->getSourceRange()))
return true;
ImpCastExprToType(From, DestType, /*isLvalue=*/true);
}
return false;
}

View File

@@ -0,0 +1,16 @@
// RUN: clang-cc -fsyntax-only -faccess-control -verify %s
class M {
int iM;
};
class P {
int iP;
int PPR();
};
class N : M,P {
N() {}
// FIXME. No access violation is reported in method call or member access.
int PR() { return iP + PPR(); }
};