]> granicus.if.org Git - clang/commitdiff
Make the AST explicitly represent the cast of the first operand of a
authorEli Friedman <eli.friedman@gmail.com>
Sat, 16 Jan 2010 00:00:48 +0000 (00:00 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 16 Jan 2010 00:00:48 +0000 (00:00 +0000)
pointer-to-member operator.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93592 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/CodeGenCXX/member-function-pointers.cpp

index 1ad931e5416aeb76a60bb599d952a3b79afe4100..e4812682a08686e467d05b671221abda3bd2b661 100644 (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())) {
index 2454ddab774a44068f9c91596e22894627557382..e1353a72b396cfb721a1faedd5ef8de123a5364a 100644 (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)();
+  }
+}