public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1793] c++: alias CTAD and aggregate deduction cand [PR98832] Date: Thu, 24 Jun 2021 17:13:44 +0000 (GMT) [thread overview] Message-ID: <20210624171344.B7B3C388A825@sourceware.org> (raw) https://gcc.gnu.org/g:c761be53f6b62e22ac5de18c4aaf88648f64f5b7 commit r12-1793-gc761be53f6b62e22ac5de18c4aaf88648f64f5b7 Author: Patrick Palka <ppalka@redhat.com> Date: Thu Jun 24 13:11:44 2021 -0400 c++: alias CTAD and aggregate deduction cand [PR98832] During alias CTAD, we're accidentally ignoring the aggregate deduction candidate for the underlying template because this guide is added separately via maybe_aggr_guide (which doesn't yet handle alias templates) instead of via deduction_guides_for (which does). This patch makes maybe_aggr_guide handle alias templates in a manner similar to deduction_guides_for. PR c++/98832 gcc/cp/ChangeLog: * pt.c (maybe_aggr_guide): Handle alias templates appropriately. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias9.C: New test. Diff: --- gcc/cp/pt.c | 11 +++++++++++ gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1af81208e26..f73c7471a33 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -28886,6 +28886,8 @@ is_spec_or_derived (tree etype, tree tmpl) return !err; } +static tree alias_ctad_tweaks (tree, tree); + /* Return a C++20 aggregate deduction candidate for TYPE initialized from INIT. */ @@ -28898,6 +28900,15 @@ maybe_aggr_guide (tree tmpl, tree init, vec<tree,va_gc> *args) if (init == NULL_TREE) return NULL_TREE; + if (DECL_ALIAS_TEMPLATE_P (tmpl)) + { + tree under = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl)); + tree tinfo = get_template_info (under); + if (tree guide = maybe_aggr_guide (TI_TEMPLATE (tinfo), init, args)) + return alias_ctad_tweaks (tmpl, guide); + return NULL_TREE; + } + /* We might be creating a guide for a class member template, e.g., template<typename U> struct A { diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C new file mode 100644 index 00000000000..5cc7b7c1a80 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C @@ -0,0 +1,6 @@ +// PR c++/98832 +// { dg-do compile { target c++20 } } + +template<class T, class U> struct X { U u; }; +template<class T> using Y = X<int, T>; +Y y{0};
reply other threads:[~2021-06-24 17:13 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=20210624171344.B7B3C388A825@sourceware.org \ --to=ppalka@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: linkBe 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).