[cfe-commits] r77497 - in /cfe/trunk/lib/Sema: Sema.h SemaExpr.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Jul 29 12:40:12 PDT 2009
Author: fjahanian
Date: Wed Jul 29 14:40:11 2009
New Revision: 77497
URL: http://llvm.org/viewvc/llvm-project?rev=77497&view=rev
Log:
Check accessibility when converting object to the base
class.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=77497&r1=77496&r2=77497&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Jul 29 14:40:11 2009
@@ -691,7 +691,7 @@
ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
bool PerformContextuallyConvertToBool(Expr *&From);
- void PerformObjectMemberConversion(Expr *&From, NamedDecl *Member);
+ bool PerformObjectMemberConversion(Expr *&From, NamedDecl *Member);
/// OverloadingResult - Capture the result of performing overload
/// resolution.
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=77497&r1=77496&r2=77497&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jul 29 14:40:11 2009
@@ -1024,7 +1024,7 @@
return BuildDeclarationNameExpr(Loc, D, HasTrailingLParen, SS, isAddressOfOperand);
}
/// \brief Cast member's object to its own class if necessary.
-void
+bool
Sema::PerformObjectMemberConversion(Expr *&From, NamedDecl *Member) {
if (FieldDecl *FD = dyn_cast<FieldDecl>(Member))
if (CXXRecordDecl *RD =
@@ -1033,11 +1033,23 @@
Context.getCanonicalType(Context.getTypeDeclType(RD));
if (!DestType->isDependentType() &&
!From->getType()->isDependentType()) {
- if (From->getType()->getAsPointerType())
+ 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);
}
}
+ return false;
}
/// \brief Complete semantic analysis for a reference to the given declaration.
@@ -1130,7 +1142,8 @@
Expr *This = new (Context) CXXThisExpr(SourceLocation(),
MD->getThisType(Context));
MarkDeclarationReferenced(Loc, D);
- PerformObjectMemberConversion(This, D);
+ if (PerformObjectMemberConversion(This, D))
+ return ExprError();
return Owned(new (Context) MemberExpr(This, true, D,
Loc, MemberType));
}
@@ -2207,7 +2220,8 @@
}
MarkDeclarationReferenced(MemberLoc, FD);
- PerformObjectMemberConversion(BaseExpr, FD);
+ if (PerformObjectMemberConversion(BaseExpr, FD))
+ return ExprError();
return Owned(new (Context) MemberExpr(BaseExpr, OpKind == tok::arrow, FD,
MemberLoc, MemberType));
}
More information about the cfe-commits
mailing list