Make the AST explicitly represent the cast of the first operand of a

pointer-to-member operator.

llvm-svn: 93592
This commit is contained in:
Eli Friedman 2010-01-16 00:00:48 +00:00
parent 6d8f59e65f
commit 1fcf66b0dd
2 changed files with 16 additions and 3 deletions

View File

@ -1450,12 +1450,14 @@ QualType Sema::CheckPointerToMemberOperands(
// overkill?
if (!IsDerivedFrom(LType, Class, Paths) ||
Paths.isAmbiguous(Context.getCanonicalType(Class))) {
const char *ReplaceStr = isIndirect ? ".*" : "->*";
Diag(Loc, diag::err_bad_memptr_lhs) << OpSpelling
<< (int)isIndirect << lex->getType() <<
CodeModificationHint::CreateReplacement(SourceRange(Loc), ReplaceStr);
<< (int)isIndirect << lex->getType();
return QualType();
}
// Cast LHS to type of use.
QualType UseType = isIndirect ? Context.getPointerType(Class) : Class;
bool isLValue = !isIndirect && lex->isLvalue(Context) == Expr::LV_Valid;
ImpCastExprToType(lex, UseType, CastExpr::CK_DerivedToBase, isLValue);
}
if (isa<CXXZeroInitValueExpr>(rex->IgnoreParens())) {

View File

@ -139,3 +139,14 @@ namespace PR5940 {
void (foo::*ptr)(void) = &foo::baz;
}
}
namespace MemberPointerImpCast {
struct A {
int x;
};
struct B : public A {
};
void f(B* obj, void (A::*method)()) {
(obj->*method)();
}
}