[Bug c++/84578] [6/7/8 Regression] ICE with flexible array member and constexpr

2018-03-02 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84578

--- Comment #4 from Marek Polacek  ---
Author: mpolacek
Date: Fri Mar  2 20:27:46 2018
New Revision: 258156

URL: https://gcc.gnu.org/viewcvs?rev=258156&root=gcc&view=rev
Log:
PR c++/84578
* constexpr.c (get_array_or_vector_nelts): New.
(cxx_eval_array_reference): Use it.
(cxx_eval_vec_init_1): Likewise.
(cxx_eval_store_expression): Likewise.

* g++.dg/ext/flexary29.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/ext/flexary29.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/constexpr.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/84578] [6/7/8 Regression] ICE with flexible array member and constexpr

2018-03-02 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84578

--- Comment #3 from Marek Polacek  ---
I think I'll leave this as it is; we give an error for

struct A
{
  constexpr A() : i(), x("foo") {}
  int i;
  char x[];
};

A a;

I have a patch for the ICE.

[Bug c++/84578] [6/7/8 Regression] ICE with flexible array member and constexpr

2018-02-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84578

Martin Sebor  changed:

   What|Removed |Added

   Keywords|ice-on-valid-code   |ice-on-invalid-code

--- Comment #2 from Martin Sebor  ---
I think the code should be rejected in constexpr contexts, as Clang does. 
Otherwise the size of A::x is zero, which would make it an invalid object.  I'm
changing it to ice-on-invalid-code but please let me know if you know of an
argument for accepting it.

[Bug c++/84578] [6/7/8 Regression] ICE with flexible array member and constexpr

2018-02-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84578

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P2

[Bug c++/84578] [6/7/8 Regression] ICE with flexible array member and constexpr

2018-02-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84578

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||mpolacek at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
   Target Milestone|--- |6.5

[Bug c++/84578] [6/7/8 Regression] ICE with flexible array member and constexpr

2018-02-26 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84578

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-02-27
 CC||msebor at gcc dot gnu.org
  Known to work||4.5.4, 5.4.0
 Ever confirmed|0   |1
  Known to fail||6.4.0, 7.3.0, 8.0

--- Comment #1 from Martin Sebor  ---
Confirmed.  The ICE was introduced by my r231665 in GCC 6.0.0:

r231665 | msebor | 2015-12-15 16:04:08 -0500 (Tue, 15 Dec 2015) | 71 lines

gcc/cp/ChangeLog:
2015-12-15  Martin Sebor  

c++/42121
c++/68478
c++/68613
c++/68689
c++/68710
* class.c (walk_subobject_offsets): Avoid assuming type domain
is non-null or has an upper bound.
(layout_class_type): Include type size in error message.
(flexmems_t): New type.
(field_nonempty_p, find_flexarrays, diagnose_flexarrays)
(check_flexarrays): New functions.
(finish_struct_1): Call check_flexarrays.
* decl.c (compute_array_index_type): Distinguish flexible array
members from zero-length arrays.
(grokdeclarator): Reject flexible array members in unions.  Avoid
rejecting members of incomplete types that are flexible array members.
* error.c (dump_type_suffix): Handle flexible array members with null
upper bound.
* init.c (perform_member_init): Same.
* pt.c (instantiate_class_template_1): Allow flexible array members.
(tsubst): Handle flexible array members with null upper bound.
* typeck2.c (digest_init_r): Warn for initialization of flexible
array members.
(process_init_constructor_record): Handle flexible array members.

gcc/ChangeLog:
2015-12-15  Martin Sebor  

c++/42121
* tree-chkp.c (chkp_find_bound_slots_1): Handle flexible array
members.
* tree.c (type_contains_placeholder_1): Avoid assuming type has
a non-null domain or an upper bound to handle flexible array
members.
* varasm.c (output_constructor_regular_field):  Same.
(output_constructor): Set min_index to integer_zero_node rather
than null when a type has no domain to avoid crashing later.