]> granicus.if.org Git - clang/commitdiff
Use CK_BitCast for member function pointer casts. Fixes PR5138.
authorAnders Carlsson <andersca@mac.com>
Sun, 18 Oct 2009 20:31:03 +0000 (20:31 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 18 Oct 2009 20:31:03 +0000 (20:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84438 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprConstant.cpp
lib/Sema/SemaCXXCast.cpp
test/CodeGenCXX/member-function-pointers.cpp

index 88fdb542f3cb41c5d3d700b38d01aa8ece968ae1..066029f9a5308e3ebee30c27ca438697b5e73dd7 100644 (file)
@@ -215,6 +215,12 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
     break;
   }
       
+  case CastExpr::CK_BitCast: {
+    // This must be a member function pointer cast.
+    Visit(E->getSubExpr());
+    break;
+  }
+
   case CastExpr::CK_BaseToDerivedMemberPointer: {
     QualType SrcType = E->getSubExpr()->getType();
     
index 7f540c3c068855848f30d815e9e27a08d68c274c..fc3748c8e3c81f6ba424af0b0e8f9211826da701 100644 (file)
@@ -542,7 +542,11 @@ public:
         return CS;
       }          
     }
-        
+
+    case CastExpr::CK_BitCast: 
+      // This must be a member function pointer cast.
+      return Visit(E->getSubExpr());
+
     default: {
       // FIXME: This should be handled by the CK_NoOp cast kind.
       // Explicit and implicit no-op casts
index 69d1f92a083237f87c0b6b676f5a884f5badd4b1..ef1d128f63dae199539f448c72b70e5d8236efb7 100644 (file)
@@ -943,6 +943,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr,
     }
 
     // A valid member pointer cast.
+    Kind = CastExpr::CK_BitCast;
     return TC_Success;
   }
 
@@ -1044,6 +1045,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr,
 
   // Not casting away constness, so the only remaining check is for compatible
   // pointer categories.
+  Kind = CastExpr::CK_BitCast;
 
   if (SrcType->isFunctionPointerType()) {
     if (DestType->isFunctionPointerType()) {
@@ -1085,8 +1087,10 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
   // This test is outside everything else because it's the only case where
   // a non-lvalue-reference target type does not lead to decay.
   // C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void".
-  if (CastTy->isVoidType())
+  if (CastTy->isVoidType()) {
+    Kind = CastExpr::CK_ToVoid;
     return false;
+  }
 
   // If the type is dependent, we won't do any other semantic analysis now.
   if (CastTy->isDependentType() || CastExpr->isTypeDependent())
index 13f7de5a631bc71f91e3cdba664fbf0bc3bde1f3..a7c21133d051397b52d87e07ce036bed08d7b77e 100644 (file)
@@ -71,3 +71,19 @@ namespace PR5177 {
 
   void bar(B1 b2) { while (b2()) ; }
 }
+
+// PR5138
+namespace PR5138 {
+  struct foo {
+      virtual void bar(foo *);
+  };
+
+  extern "C" {
+    void baz(foo *);
+  }
+  
+  void (foo::*ptr1)(void *) = (void (foo::*)(void *))&foo::bar;
+  void (*ptr2)(void *) = (void (*)(void *))&baz;
+
+  void (foo::*ptr3)(void) = (void (foo::*)(void))&foo::bar;
+}