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.
===================================================================
@@ -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
===================================================================
@@ -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;
+}