This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/46688 (incorrect error with flexible array in constructor)


build_vec_init_expr builds a single constructor call in order to mark the constructor as used and get any appropriate diagnostics. But in the case of a flexible array, initializing it won't actually call any constructors because it has no members, so we need to check for that case.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 30f32022b48840f117da0b5b9e75d8329cbd82e3
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 12 19:02:01 2011 -0500

    	PR c++/46688
    	* tree.c (build_vec_init_expr): Handle flexible array
    	properly.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 213279a..813b88d 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -474,7 +474,12 @@ build_vec_init_expr (tree type, tree init)
      what functions are needed.  Here we assume that init is either
      NULL_TREE, void_type_node (indicating value-initialization), or
      another array to copy.  */
-  if (init == void_type_node)
+  if (integer_zerop (array_type_nelts_total (type)))
+    {
+      /* No actual initialization to do.  */;
+      init = NULL_TREE;
+    }
+  else if (init == void_type_node)
     {
       elt_init = build_value_init (inner_type, tf_warning_or_error);
       value_init = true;
diff --git a/gcc/testsuite/g++.dg/ext/flexary2.C b/gcc/testsuite/g++.dg/ext/flexary2.C
new file mode 100644
index 0000000..4855b3f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/flexary2.C
@@ -0,0 +1,11 @@
+// PR c++/46688
+// { dg-options "" }
+
+struct A {
+   A(int);
+};
+
+struct B {
+   B() {}
+   A a[];
+};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]