PR c++/89212 - ICE converting nullptr to pointer-to-member-function.
authorMarek Polacek <polacek@redhat.com>
Mon, 11 Feb 2019 20:03:43 +0000 (20:03 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 11 Feb 2019 20:03:43 +0000 (20:03 +0000)
* pt.c (tsubst_copy_and_build) <case CONSTRUCTOR>: Return early for
null member pointer value.

* g++.dg/cpp0x/nullptr40.C: New test.
* g++.dg/cpp0x/nullptr41.C: New test.

From-SVN: r268781

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nullptr40.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nullptr41.C [new file with mode: 0644]

index 3bfd06f..3d3bb2a 100644 (file)
@@ -1,3 +1,9 @@
+2019-02-11  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89212 - ICE converting nullptr to pointer-to-member-function.
+       * pt.c (tsubst_copy_and_build) <case CONSTRUCTOR>: Return early for
+       null member pointer value.
+
 2019-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/88977
index eb17976..184cb85 100644 (file)
@@ -19253,6 +19253,12 @@ tsubst_copy_and_build (tree t,
           looked up by digest_init.  */
        process_index_p = !(type && MAYBE_CLASS_TYPE_P (type));
 
+       if (null_member_pointer_value_p (t))
+         {
+           gcc_assert (same_type_p (type, TREE_TYPE (t)));
+           RETURN (t);
+         }
+
        n = vec_safe_copy (CONSTRUCTOR_ELTS (t));
         newlen = vec_safe_length (n);
        FOR_EACH_VEC_SAFE_ELT (n, idx, ce)
index afcf630..ae04c4b 100644 (file)
@@ -1,3 +1,9 @@
+2019-02-11  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89212 - ICE converting nullptr to pointer-to-member-function.
+       * g++.dg/cpp0x/nullptr40.C: New test.
+       * g++.dg/cpp0x/nullptr41.C: New test.
+
 2019-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/88977
diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr40.C b/gcc/testsuite/g++.dg/cpp0x/nullptr40.C
new file mode 100644 (file)
index 0000000..21c188b
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/89212
+// { dg-do compile { target c++11 } }
+
+template <int, typename T> using enable_if_t = int;
+
+template<class X, void(X::*foo)() = nullptr>
+struct p
+{
+    template<void(X::*fun)() = foo, typename T = enable_if_t<nullptr == fun, int>>
+    p(T) { }
+    p() = default;
+};
+
+struct A
+{
+    p<A> i = 1;
+    void bar();
+    p<A, &A::bar> j;
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr41.C b/gcc/testsuite/g++.dg/cpp0x/nullptr41.C
new file mode 100644 (file)
index 0000000..54e66af
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/89212
+// { dg-do compile { target c++11 } }
+
+template <int, typename T> using enable_if_t = int;
+
+template<typename U, typename W, typename Y, class X, W(X::*foo)() = nullptr>
+struct p
+{
+    template<U(Y::*fun)() = foo, typename T = enable_if_t<nullptr == fun, int>>
+    p(T) { }
+    p() = default;
+};
+
+struct A
+{
+    p<void, void, A, A> i = 1;
+    void bar();
+    p<void, void, A, A, &A::bar> j;
+};