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-1373] c++: normalization of non-templated return-type-req [PR100946] Date: Thu, 10 Jun 2021 22:33:28 +0000 (GMT) [thread overview] Message-ID: <20210610223328.2433638515E0@sourceware.org> (raw) https://gcc.gnu.org/g:206db06ee380f490db0293af4ea7a4d590abd78c commit r12-1373-g206db06ee380f490db0293af4ea7a4d590abd78c Author: Patrick Palka <ppalka@redhat.com> Date: Thu Jun 10 18:31:18 2021 -0400 c++: normalization of non-templated return-type-req [PR100946] Here the satisfaction cache is conflating the satisfaction value of the two return-type-requirements because the corresponding constrained 'auto's have level 2, but they capture an empty current_template_parms. This ultimately causes the satisfaction cache to think the type constraint doesn't depend on the deduced type of the expression. When normalizing the constraints on an 'auto', the assumption made by normalize_placeholder_type_constraints is that the level of the 'auto' is one greater than the depth of the captured current_template_parms, an assumption which is not holding here. So this patch just makes n_p_t_c adjust the normalization context appropriately in this situation. PR c++/100946 gcc/cp/ChangeLog: * constraint.cc (normalize_placeholder_type_constraints): When normalizing a non-templated return-type-requirement, add a dummy level to initial_parms. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-return-req3.C: New test. Diff: --- gcc/cp/constraint.cc | 9 +++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-return-req3.C | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 03ce8eb9ff2..74b16d27101 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3065,6 +3065,15 @@ normalize_placeholder_type_constraints (tree t, bool diag) scope for this placeholder type; use them as the initial template parameters for normalization. */ tree initial_parms = TREE_PURPOSE (ci); + + if (!initial_parms && TEMPLATE_TYPE_LEVEL (t) == 2) + /* This is a return-type-requirement of a non-templated requires-expression, + which are parsed under processing_template_decl == 1 and empty + current_template_parms; hence the 'auto' has level 2 and initial_parms + is empty. Fix up initial_parms to be consistent with the value of + processing_template_decl whence the 'auto' was created. */ + initial_parms = build_tree_list (size_int (1), make_tree_vec (0)); + /* The 'auto' itself is used as the first argument in its own constraints, and its level is one greater than its template depth. So in order to capture all used template parameters, we need to add an extra level of diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-return-req3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-return-req3.C new file mode 100644 index 00000000000..a546c6457be --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-return-req3.C @@ -0,0 +1,6 @@ +// PR c++/100946 +// { dg-do compile { target c++20 } } + +template<class T> concept C = __is_same(T, int); +static_assert(requires { { 0 } -> C; }); +static_assert(requires { { true } -> C; }); // { dg-error "failed" }
reply other threads:[~2021-06-10 22:33 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=20210610223328.2433638515E0@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).