]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: array of PMF [PR113598]
authorJason Merrill <jason@redhat.com>
Thu, 25 Jan 2024 17:02:07 +0000 (12:02 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 24 May 2024 18:38:04 +0000 (14:38 -0400)
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.c (build_vec_init): Don't use {} for PMF.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-pmf2.C: New test.

(cherry picked from commit 136a828754ff65079a834555582b49d54bd5bc64)

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

index 08b26ba9a17855897e83bb0ed03ca359aef94760..b6e63ee8f2833bcd45543a1354543952cdf450c7 100644 (file)
@@ -4479,7 +4479,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 (file)
index 0000000..59c3698
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/113598
+// { dg-additional-options -w }
+
+struct Cpu
+{
+  int op_nop();
+};
+typedef int(Cpu::*OpCode)();
+void f()
+{
+  new OpCode[256]{&Cpu::op_nop};
+}