Message ID | 20200930075708.GF2176@tucnak |
---|---|
State | New |
Headers | show |
Series | [v2] c++: Fix up default initialization with consteval default ctor [PR96994] | expand |
On 9/30/20 3:57 AM, Jakub Jelinek wrote: > On Fri, Sep 25, 2020 at 04:30:26PM -0400, Jason Merrill via Gcc-patches wrote: >> On 9/15/20 3:57 AM, Jakub Jelinek wrote: >>> The following testcase is miscompiled (in particular the a and i >>> initialization). The problem is that build_special_member_call due to >>> the immediate constructors (but not evaluated in constant expression mode) >>> doesn't create a CALL_EXPR, but returns a TARGET_EXPR with CONSTRUCTOR >>> as the initializer for it, >> >> That seems like the bug; at the end of build_over_call, after you >> >>> call = cxx_constant_value (call, obj_arg); >> >> You need to build an INIT_EXPR if obj_arg isn't a dummy. > > That works. obj_arg is NULL if it is a dummy from the earlier code. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?1 OK. > 2020-09-30 Jakub Jelinek <jakub@redhat.com> > > PR c++/96994 > * call.c (build_over_call): If obj_arg is non-NULL, return INIT_EXPR > setting obj_arg to call. > > * g++.dg/cpp2a/consteval18.C: New test. > > --- gcc/cp/call.c.jj 2020-09-10 15:52:50.688207138 +0200 > +++ gcc/cp/call.c 2020-09-29 20:39:55.003361651 +0200 > @@ -9200,6 +9200,8 @@ build_over_call (struct z_candidate *can > } > } > call = cxx_constant_value (call, obj_arg); > + if (obj_arg && !error_operand_p (call)) > + call = build2 (INIT_EXPR, void_type_node, obj_arg, call); > } > } > return call; > --- gcc/testsuite/g++.dg/cpp2a/consteval18.C.jj 2020-09-29 20:33:56.533596845 +0200 > +++ gcc/testsuite/g++.dg/cpp2a/consteval18.C 2020-09-29 20:33:56.533596845 +0200 > @@ -0,0 +1,26 @@ > +// PR c++/96994 > +// { dg-do run { target c++20 } } > + > +struct A { consteval A () { i = 1; } consteval A (int x) : i (x) {} int i = 0; }; > +struct B { constexpr B () { i = 1; } constexpr B (int x) : i (x) {} int i = 0; }; > +A const a; > +constexpr A b; > +B const c; > +A const constinit d; > +A const e = 2; > +constexpr A f = 3; > +B const g = 4; > +A const constinit h = 5; > +A i; > +B j; > +A k = 6; > +B l = 7; > +static_assert (b.i == 1 && f.i == 3); > + > +int > +main() > +{ > + if (a.i != 1 || c.i != 1 || d.i != 1 || e.i != 2 || g.i != 4 || h.i != 5 > + || i.i != 1 || j.i != 1 || k.i != 6 || l.i != 7) > + __builtin_abort (); > +} > > > Jakub >
--- gcc/cp/call.c.jj 2020-09-10 15:52:50.688207138 +0200 +++ gcc/cp/call.c 2020-09-29 20:39:55.003361651 +0200 @@ -9200,6 +9200,8 @@ build_over_call (struct z_candidate *can } } call = cxx_constant_value (call, obj_arg); + if (obj_arg && !error_operand_p (call)) + call = build2 (INIT_EXPR, void_type_node, obj_arg, call); } } return call; --- gcc/testsuite/g++.dg/cpp2a/consteval18.C.jj 2020-09-29 20:33:56.533596845 +0200 +++ gcc/testsuite/g++.dg/cpp2a/consteval18.C 2020-09-29 20:33:56.533596845 +0200 @@ -0,0 +1,26 @@ +// PR c++/96994 +// { dg-do run { target c++20 } } + +struct A { consteval A () { i = 1; } consteval A (int x) : i (x) {} int i = 0; }; +struct B { constexpr B () { i = 1; } constexpr B (int x) : i (x) {} int i = 0; }; +A const a; +constexpr A b; +B const c; +A const constinit d; +A const e = 2; +constexpr A f = 3; +B const g = 4; +A const constinit h = 5; +A i; +B j; +A k = 6; +B l = 7; +static_assert (b.i == 1 && f.i == 3); + +int +main() +{ + if (a.i != 1 || c.i != 1 || d.i != 1 || e.i != 2 || g.i != 4 || h.i != 5 + || i.i != 1 || j.i != 1 || k.i != 6 || l.i != 7) + __builtin_abort (); +}