8sa1-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-array22.C
Jason Merrill e0804c9b5e PR c++/93143 - incorrect tree sharing with constexpr.
We don't unshare CONSTRUCTORs as often during constexpr evaluation, so we
need to unshare them here.

	* constexpr.c (cxx_eval_outermost_constant_expr): Don't assume
	CONSTRUCTORs are already unshared.

From-SVN: r280127
2020-01-10 13:47:02 -05:00

28 lines
342 B
C

// PR c++/93143
// { dg-do run { target c++11 } }
struct A { char a[2]; };
static constexpr A foo () { return A{1}; }
void bar ()
{
A a = foo ();
if (a.a[0] != 1)
__builtin_abort();
}
void foobar ()
{
A x[] = { foo (), foo () };
A a = foo ();
if (a.a[0] != 1)
__builtin_abort();
}
int main()
{
bar();
foobar();
}