Avoid ICE on pmf{} in template.
authorJason Merrill <jason@redhat.com>
Fri, 12 Apr 2019 16:25:59 +0000 (12:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 12 Apr 2019 16:25:59 +0000 (12:25 -0400)
Now that we return the original CONSTRUCTOR from finish_compound_literal,
the call to null_member_pointer_value_p in tsubst_copy_and_build was getting
confused because the CONSTRUCTOR was still empty rather than a valid PMF
value.

* call.c (null_member_pointer_value_p): Handle an empty CONSTRUCTOR
of PMF type.

From-SVN: r270324

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/initlist-pmf1.C [new file with mode: 0644]

index 8e63fdaac74b36fa048ef34f1230c17957496f1d..8b2e7574450e1f49778f58498231ea4b3dcf3994 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-12  Jason Merrill  <jason@redhat.com>
+
+       * call.c (null_member_pointer_value_p): Handle an empty CONSTRUCTOR
+       of PMF type.
+
 2019-04-12  Marek Polacek  <polacek@redhat.com>
 
        * except.c (build_noexcept_spec): Use build_converted_constant_bool_expr
index 519dad9bf2c2703b61fccde676c8f94c3027e98c..9582345d7e828d38f66d4342ed22d1f369deb84a 100644 (file)
@@ -569,6 +569,7 @@ null_member_pointer_value_p (tree t)
     return false;
   else if (TYPE_PTRMEMFUNC_P (type))
     return (TREE_CODE (t) == CONSTRUCTOR
+           && CONSTRUCTOR_NELTS (t)
            && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
   else if (TYPE_PTRDATAMEM_P (type))
     return integer_all_onesp (t);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-pmf1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-pmf1.C
new file mode 100644 (file)
index 0000000..3035fef
--- /dev/null
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  void f();
+};
+
+using ftype = decltype(&A::f);
+
+template <class T>
+bool f()
+{
+  ftype p = ftype{};
+  return p;
+}
+
+int main()
+{
+  f<int>();
+}