In the testcase below, the CONSTRUCTOR for 'field' contains a RANGE_EXPR
index:
{{aggr_init_expr<...>, [1...2]={.off=1}}}
but get_or_insert_ctor_field isn't prepared to handle looking up a
RANGE_EXPR index.
This patch adds limited support to get_or_insert_ctor_field for looking
up a RANGE_EXPR index. The limited scope of this patch should make it
more suitable for backporting, and more extensive support would be
needed only to handle self-modifying CONSTRUCTORs that contain a
RANGE_EXPR index, but I haven't yet been able to come up with a testcase
that actually creates such a CONSTRUCTOR.
gcc/cp/ChangeLog:
PR c++/95241
* constexpr.c (get_or_insert_ctor_field): Add limited support
for RANGE_EXPR index lookups.
gcc/testsuite/ChangeLog:
PR c++/95241
* g++.dg/cpp0x/constexpr-array25.C: New test.
22 lines
421 B
C
22 lines
421 B
C
// PR c++/95241
|
|
// { dg-do compile { target c++11 } }
|
|
|
|
struct Fragment
|
|
{
|
|
int off;
|
|
constexpr Fragment(int _off) : off(_off) { }
|
|
constexpr Fragment() : Fragment(1) { }
|
|
};
|
|
|
|
struct Field
|
|
{
|
|
Fragment fragments[3];
|
|
constexpr Field(int off) : fragments{{off}} { }
|
|
};
|
|
|
|
constexpr Field field{0};
|
|
|
|
static_assert(field.fragments[0].off == 0
|
|
&& field.fragments[1].off == 1
|
|
&& field.fragments[2].off == 1, "");
|