[pushed] c++: array of PMF [PR113598]

Message ID 20240125202216.1228203-1-jason@redhat.com
State Accepted
Headers
Series [pushed] c++: array of PMF [PR113598] |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Jason Merrill Jan. 25, 2024, 8:22 p.m. UTC
  Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Here AGGREGATE_TYPE_P includes pointers to member functions, which is not
what we want.  Instead we should use class||array, as elsewhere in the
function.

	PR c++/113598

gcc/cp/ChangeLog:

	* init.cc (build_vec_init): Don't use {} for PMF.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/initlist-pmf2.C: New test.
---
 gcc/cp/init.cc                             |  4 +++-
 gcc/testsuite/g++.dg/cpp0x/initlist-pmf2.C | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-pmf2.C


base-commit: c6c2a1d79eb333a00124bf67820a7f405d0d8641
prerequisite-patch-id: 32204a3e8393a5c133fa74b57979c77cd7742149
  

Patch

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index adbdfc2dbfc..ac37330527e 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4864,7 +4864,9 @@  build_vec_init (tree base, tree maxindex, tree init,
 	 But for non-classes, that's the same as value-initialization.  */
       if (empty_list)
 	{
-	  if (cxx_dialect >= cxx11 && AGGREGATE_TYPE_P (type))
+	  if (cxx_dialect >= cxx11
+	      && (CLASS_TYPE_P (type)
+		  || TREE_CODE (type) == ARRAY_TYPE))
 	    {
 	      init = build_constructor (init_list_type_node, NULL);
 	    }
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-pmf2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-pmf2.C
new file mode 100644
index 00000000000..0fac8333c75
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-pmf2.C
@@ -0,0 +1,12 @@ 
+// PR c++/113598
+// { dg-additional-options -Wno-c++11-extensions }
+
+struct Cpu
+{
+  int op_nop();
+};
+typedef int(Cpu::*OpCode)();
+void f()
+{
+  new OpCode[256]{&Cpu::op_nop};
+}