]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/65695 (NSDMI calling constexpr constructor with pointer-to-member is not...
authorJason Merrill <jason@redhat.com>
Thu, 23 Apr 2015 13:21:17 +0000 (09:21 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 23 Apr 2015 13:21:17 +0000 (09:21 -0400)
PR c++/65695
* cvt.c (cp_fold_convert): Avoid wrapping PTRMEM_CST in NOP_EXPR.

From-SVN: r222367

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem4.C [new file with mode: 0644]

index 0166bee588bfef7d64790cfacf96ed9cb2093d84..27fd9a9de024729cd38d2849f817910306d6a072 100644 (file)
@@ -1,5 +1,8 @@
 2015-04-23  Jason Merrill  <jason@redhat.com>
 
+       PR c++/65695
+       * cvt.c (cp_fold_convert): Avoid wrapping PTRMEM_CST in NOP_EXPR.
+
        PR c++/65721
        * name-lookup.c (do_class_using_decl): Complain about specifying
        the current class even if there are dependent bases.
index e8ece0e0b13206057e5a9d8a545142abfd5d8318..adfe7c6575f5ff3f99c200cf7eedca679505586b 100644 (file)
@@ -595,8 +595,20 @@ ignore_overflows (tree expr, tree orig)
 tree
 cp_fold_convert (tree type, tree expr)
 {
-  tree conv = fold_convert (type, expr);
-  conv = ignore_overflows (conv, expr);
+  tree conv;
+  if (TREE_TYPE (expr) == type)
+    conv = expr;
+  else if (TREE_CODE (expr) == PTRMEM_CST)
+    {
+      /* Avoid wrapping a PTRMEM_CST in NOP_EXPR.  */
+      conv = copy_node (expr);
+      TREE_TYPE (conv) = type;
+    }
+  else
+    {
+      conv = fold_convert (type, expr);
+      conv = ignore_overflows (conv, expr);
+    }
   return conv;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem4.C
new file mode 100644 (file)
index 0000000..68788ca
--- /dev/null
@@ -0,0 +1,26 @@
+// PR c++/65695
+// { dg-do compile { target c++11 } }
+
+struct Foo;
+
+struct Bar
+{
+    using MemberFuncT = int (Foo::*)();
+
+    MemberFuncT h_;
+    constexpr Bar(MemberFuncT h) : h_{h}
+    {
+    }
+};
+
+struct Foo
+{
+    int test()
+    {
+        return -1;
+    }
+
+    static constexpr Bar bar {&Foo::test};
+};
+
+constexpr Bar Foo::bar;