]> granicus.if.org Git - clang/commitdiff
Add code gen for pointer-to-member function in
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 4 Nov 2009 19:13:37 +0000 (19:13 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 4 Nov 2009 19:13:37 +0000 (19:13 +0000)
ctor's initializer. Fixes pr5178.

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

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/ptr-to-member-function.cpp

index d8b532e697ba095bf3a6dbc8714f9b721a2e1c3f..d4adbad1e45e240f68484a9832ab84aa11fcb304 100644 (file)
@@ -1421,6 +1421,8 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
       if (FieldType->isReferenceType())
         RHS = EmitReferenceBindingToExpr(RhsExpr, FieldType,
                                         /*IsInitializer=*/true);
+      else if (FieldType->isMemberFunctionPointerType())
+        RHS = RValue::get(CGM.EmitConstantExpr(RhsExpr, FieldType, this));
       else
         RHS = RValue::get(EmitScalarExpr(RhsExpr, true));
       EmitStoreThroughLValue(RHS, LHS, FieldType);
index 1e396e976575d0a16fb464abde43e5ffd8791bf7..15019081c0620fdfea2b6652d98f59ee758b1129 100644 (file)
@@ -9,8 +9,14 @@ extern "C" int printf(...);
 
 struct A {
 int Ai;
+bool foo(int* arg) const;
 }; 
 
+bool A::foo(int* arg) const {
+    printf("A::foo(%d)\n", *arg);
+    return true;
+}
+
 struct B : public A {
   void bf() { printf("B::bf called\n"); }
 }; 
@@ -40,10 +46,22 @@ void test2(X x)
     g(x);
 }
 
+struct B1 {
+  bool (A::*pmf)(int*) const;
+
+  B1(int i) : pmf(&A::foo), im(i) {
+    ((A*)this->*pmf)(&im);
+  }
+
+  int im;
+};
+
 int main()
 {
        X x;
        test2(x);
+        B1 b = B1(1);
+       B1 c = B1(2);
 }
 
 // CHECK-LP64: call    __ZN1XcvM1BFvvEEv