summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-04 12:57:49 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-04 12:57:49 +0000
commit125fa40c34a4bd6ecdce1156e5889063a688ef77 (patch)
tree3463891a7666ba3a9671f372c87a345147ace84b /clang/lib
parent5a3ff5b5a09d8445e5f3f51d198b8b7c3668473e (diff)
downloadbcm5719-llvm-125fa40c34a4bd6ecdce1156e5889063a688ef77.tar.gz
bcm5719-llvm-125fa40c34a4bd6ecdce1156e5889063a688ef77.zip
When calling a bound pointer to member function, check the
cv-qualifiers on the object against the cv-qualifiers on the member function. Fixes PR8315. llvm-svn: 124865
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 01fc1c4e6f5..0d4950fd16c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4328,6 +4328,26 @@ Sema::ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
QualType ResultTy = FPT->getCallResultType(Context);
ExprValueKind VK = Expr::getValueKindForType(FPT->getResultType());
+ // Check that the object type isn't more qualified than the
+ // member function we're calling.
+ Qualifiers FuncQuals = Qualifiers::fromCVRMask(FPT->getTypeQuals());
+ Qualifiers ObjectQuals
+ = BO->getOpcode() == BO_PtrMemD
+ ? BO->getLHS()->getType().getQualifiers()
+ : BO->getLHS()->getType()->getAs<PointerType>()
+ ->getPointeeType().getQualifiers();
+
+ Qualifiers Difference = ObjectQuals - FuncQuals;
+ Difference.removeObjCGCAttr();
+ Difference.removeAddressSpace();
+ if (Difference) {
+ std::string QualsString = Difference.getAsString();
+ Diag(LParenLoc, diag::err_pointer_to_member_call_drops_quals)
+ << BO->getType().getUnqualifiedType()
+ << QualsString
+ << (QualsString.find(' ') == std::string::npos? 1 : 2);
+ }
+
CXXMemberCallExpr *TheCall
= new (Context) CXXMemberCallExpr(Context, Fn, Args,
NumArgs, ResultTy, VK,
OpenPOWER on IntegriCloud