From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id A82A2385803D; Mon, 28 Mar 2022 19:13:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A82A2385803D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9705] c++: missing aggregate base ctor [PR102045] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 97390a9914672f5ce73c169b3ae7fd4bba25c2fe X-Git-Newrev: 14146bb58f279659279cd189bf95c3b0cb5fe1ac Message-Id: <20220328191302.A82A2385803D@sourceware.org> Date: Mon, 28 Mar 2022 19:13:02 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Mar 2022 19:13:02 -0000 https://gcc.gnu.org/g:14146bb58f279659279cd189bf95c3b0cb5fe1ac commit r11-9705-g14146bb58f279659279cd189bf95c3b0cb5fe1ac Author: Jason Merrill Date: Sat Mar 26 20:38:54 2022 -0400 c++: missing aggregate base ctor [PR102045] When make_base_init_ok changes a call to a complete constructor into a call to a base constructor, we were never marking the base ctor as used, so it didn't get emitted. PR c++/102045 gcc/cp/ChangeLog: * call.c (make_base_init_ok): Call make_used. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/aggr-base12.C: New test. Diff: --- gcc/cp/call.c | 1 + gcc/testsuite/g++.dg/cpp1z/aggr-base12.C | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 5e5bc97f63b..f8b964a96da 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8643,6 +8643,7 @@ make_base_init_ok (tree exp) call target. It would be possible to splice in the appropriate arguments, but probably not worth the complexity. */ return false; + mark_used (fn); AGGR_INIT_EXPR_FN (exp) = build_address (fn); return true; } diff --git a/gcc/testsuite/g++.dg/cpp1z/aggr-base12.C b/gcc/testsuite/g++.dg/cpp1z/aggr-base12.C new file mode 100644 index 00000000000..6f5a6b2056a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/aggr-base12.C @@ -0,0 +1,24 @@ +// PR c++/102045 +// { dg-do link { target c++17 } } + +template +struct span +{ + template + constexpr span(T (&a)[N]) : data(a), len(N) { } + constexpr bool empty() const { return len == 0; } + T* data; + unsigned long len; +}; + +struct byte_writer: span { + constexpr void do_something() noexcept { + (void)this->empty(); + } +}; + +int main() { + char array[1]; + auto writer = byte_writer{array}; + writer.do_something(); +}