public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7850] c++: missing aggregate base ctor [PR102045]
Date: Mon, 28 Mar 2022 13:37:17 +0000 (GMT)	[thread overview]
Message-ID: <20220328133717.C1083385782D@sourceware.org> (raw)

https://gcc.gnu.org/g:72bdfcb848327020f62f72405d72cf85650666e1

commit r12-7850-g72bdfcb848327020f62f72405d72cf85650666e1
Author: Jason Merrill <jason@redhat.com>
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.cc (make_base_init_ok): Call make_used.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1z/aggr-base12.C: New test.

Diff:
---
 gcc/cp/call.cc                           |  1 +
 gcc/testsuite/g++.dg/cpp1z/aggr-base12.C | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index dfe370d685d..73fede5a3df 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -8958,6 +8958,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<typename T>
+struct span
+{
+  template<unsigned long N>
+  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<char> {
+  constexpr void do_something() noexcept {
+    (void)this->empty();
+  }
+};
+
+int main() {
+  char array[1];
+  auto writer = byte_writer{array};
+  writer.do_something();
+}


                 reply	other threads:[~2022-03-28 13:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220328133717.C1083385782D@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).