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 r13-769] c++: CTAD with alias and nested template [PR105655] Date: Wed, 25 May 2022 18:50:01 +0000 (GMT) [thread overview] Message-ID: <20220525185001.AEEA1383066A@sourceware.org> (raw) https://gcc.gnu.org/g:34970d08c6297e12f3f9117b6ac19fb2de522e24 commit r13-769-g34970d08c6297e12f3f9117b6ac19fb2de522e24 Author: Jason Merrill <jason@redhat.com> Date: Wed May 25 12:38:58 2022 -0400 c++: CTAD with alias and nested template [PR105655] Here, alias_ctad_tweaks expect tsubst_decl of a FUNCTION_DECL to return a FUNCTION_DECL. A reasonable expectation, but in this case we were replacing the template args of the class-scope deduction guide with equivalent args, so looking in the hash table we found the partial instantiation stored when instantiating A<int>, which is a TEMPLATE_DECL. It's fine for that to be what is stored, but tsubst_function_decl should never return it. PR c++/105655 gcc/cp/ChangeLog: * pt.cc (build_template_decl): Add assert. (tsubst_function_decl): Don't return a template. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias13.C: New test. Diff: --- gcc/cp/pt.cc | 6 +++++- .../g++.dg/cpp2a/class-deduction-alias13.C | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 76913cb1409..021af019840 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -5021,6 +5021,8 @@ maybe_update_decl_type (tree orig_type, tree scope) static tree build_template_decl (tree decl, tree parms, bool member_template_p) { + gcc_checking_assert (TREE_CODE (decl) != TEMPLATE_DECL); + tree tmpl = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), NULL_TREE); SET_DECL_LANGUAGE (tmpl, DECL_LANGUAGE (decl)); DECL_TEMPLATE_PARMS (tmpl) = parms; @@ -14074,7 +14076,9 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, { hash = hash_tmpl_and_args (gen_tmpl, argvec); if (tree spec = retrieve_specialization (gen_tmpl, argvec, hash)) - return spec; + /* The spec for these args might be a partial instantiation of the + template, but here what we want is the FUNCTION_DECL. */ + return STRIP_TEMPLATE (spec); } } else diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C new file mode 100644 index 00000000000..0a90a83081b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C @@ -0,0 +1,24 @@ +// PR c++/105655 +// { dg-do compile { target c++20 } } + +template <class T> +struct A +{ + template <class L, class R> + struct B + { + B(const L & left, const R & right) + {} + }; + + template <class L, class R> + B(const L &, const R &) -> B<L, R>; +}; + +template <class L, class R> +using C = A<int>::B<L, R>; + +int main() +{ + C x{0, 0}; +}
reply other threads:[~2022-05-25 18:50 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=20220525185001.AEEA1383066A@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: 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).