[cfe-commits] r93592 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/member-function-pointers.cpp
Eli Friedman
eli.friedman at gmail.com
Fri Jan 15 16:00:49 PST 2010
Author: efriedma
Date: Fri Jan 15 18:00:48 2010
New Revision: 93592
URL: http://llvm.org/viewvc/llvm-project?rev=93592&view=rev
Log:
Make the AST explicitly represent the cast of the first operand of a
pointer-to-member operator.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=93592&r1=93591&r2=93592&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Jan 15 18:00:48 2010
@@ -1450,12 +1450,14 @@
// 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())) {
Modified: cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp?rev=93592&r1=93591&r2=93592&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp Fri Jan 15 18:00:48 2010
@@ -139,3 +139,14 @@
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)();
+ }
+}
More information about the cfe-commits
mailing list