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]

[PATCH] #69290 - [6 Regression] ICE on invalid initialization of a flexible array member


The attached patch fixes another ICE triggered by an invalid
initialization of a flexible array member, and caused by making
the upper bound of the TYPE_DOMAIN() of such arrays null.

Martin

PS Jason, when you have a chance, there are two other patches
for similar P1 failures waiting for your review:

[PATCH] fix #69251 - [6 Regression] ICE in unify_array_domain on
  a flexible array member
  https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01348.html

[PATCH] fix #69253 - [6 Regression] ICE in
   cxx_incomplete_type_diagnostic initializing a flexible array
   member with empty string
   https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01325.html
PR c++/69290 - [6 Regression] ICE on invalid initialization of a flexible
    array member

gcc/testsuite/ChangeLog:
2016-01-21  Martin Sebor  <msebor@redhat.com>

	PR c++/69290
	* g++.dg/ext/flexary12.C: New test.

gcc/cp/ChangeLog:
2016-01-21  Martin Sebor  <msebor@redhat.com>

	PR c++/69290
	* tree.c (array_of_runtime_bound_p): Handle flexible array members.
Index: gcc/cp/tree.c
===================================================================
--- gcc/cp/tree.c	(revision 232692)
+++ gcc/cp/tree.c	(working copy)
@@ -937,9 +937,12 @@ array_of_runtime_bound_p (tree t)
   tree dom = TYPE_DOMAIN (t);
   if (!dom)
     return false;
-  tree max = TYPE_MAX_VALUE (dom);
-  return (!potential_rvalue_constant_expression (max)
-	  || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
+  if (tree max = TYPE_MAX_VALUE (dom))
+    return (!potential_rvalue_constant_expression (max)
+	    || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
+
+  /* Flexible array members have no upper bound.  */
+  return false;
 }
 
 /* Return a reference type node referring to TO_TYPE.  If RVAL is
Index: gcc/testsuite/g++.dg/ext/flexary12.C
===================================================================
--- gcc/testsuite/g++.dg/ext/flexary12.C	(revision 0)
+++ gcc/testsuite/g++.dg/ext/flexary12.C	(working copy)
@@ -0,0 +1,63 @@
+// PR c++/69290 - [6 Regression] g++ ICE on invalid initialization
+//     of a flexible array member
+// { dg-do compile }
+
+// Suppress pedantic errors about initialization of a flexible array member.
+// { dg-options "-Wno-pedantic" }
+
+struct A {
+  int a [];  // { dg-error "flexible array member .A::a. in an otherwise empty .struct A." }
+};
+
+void f1 ()
+{
+  // This is the meat of the test from c++/69290:
+  struct A a
+    = { "c" };   // { dg-error "invalid conversion from .const char\\*. to .int." }
+
+  (void)&a;
+}
+
+
+// Exercise other forms of invalid initialization besides the one in the bug.
+struct B {
+  int n;
+  int a [];
+};
+
+void f2 ()
+{
+  struct B b1
+    = { 0, "c" };   // { dg-error "invalid conversion from .const char\\*. to .int." }
+
+  (void)&b1;
+
+  const char s[] = "c";
+  struct B b2
+    = { 0, s };   // { dg-error "invalid conversion from .const char\\*. to .int." }
+
+  (void)&b2;
+}
+
+struct D {
+  int a [];  // { dg-error "flexible array member .D::a. in an otherwise empty .struct D." }
+  D ();
+};
+
+D::D ():
+  a ("c")   // { dg-error "incompatible types in assignment of .const char \\\[2\\\]. to .int \\\[\\\]." }
+{ }
+
+
+template <class T>
+struct C {
+  T a [];  // { dg-error "flexible array member" }
+};
+
+void f3 ()
+{
+  struct C<double> cd
+    = { "c" };   // { dg-error "cannot convert .const char\\*. to .double." }
+
+  (void)&cd;
+}

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