c++: Fix copy elision for base initialization
authorJason Merrill <jason@redhat.com>
Wed, 13 Jan 2021 18:27:53 +0000 (13:27 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 15 Jan 2021 18:57:01 +0000 (13:57 -0500)
commit424deca72b63e644cbc975cbc2fdda5248449bcb
tree89767d1681fe4b2357093bb87e013dbbaaf179ca
parentad2603433853129e847cade5e269c6a5f889a020
c++: Fix copy elision for base initialization

While working on PR98642 I noticed that in this testcase we were eliding the
copy, calling the complete default constructor to initialize the B base
subobject, and therefore wrongly initializing the non-existent A subobject
of B.  The test doesn't care whether the copy is elided or not, but checks
that we are actually calling a base constructor for B.

The patch preserves the elision, but changes the initializer to call the
base constructor instead of the complete constructor.

gcc/cp/ChangeLog:

* call.c (base_ctor_for, make_base_init_ok): New.
(build_over_call): Use make_base_init_ok.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/elide4.C: New test.
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp1z/elide4.C [new file with mode: 0644]