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 8e63fda..8b2e757 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 519dad9..9582345 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>();
+}