From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id BF11D3858400; Sun, 19 Dec 2021 19:10:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF11D3858400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9401] c++: local_specializations and recursive constrained fn [PR103714] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: bcadb4f31f6774548bb3e97a50967e56e9b3290a X-Git-Newrev: 75d95f5f0151247c39f0beb01376485806d0fd47 Message-Id: <20211219191020.BF11D3858400@sourceware.org> Date: Sun, 19 Dec 2021 19:10:20 +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: Sun, 19 Dec 2021 19:10:20 -0000 https://gcc.gnu.org/g:75d95f5f0151247c39f0beb01376485806d0fd47 commit r11-9401-g75d95f5f0151247c39f0beb01376485806d0fd47 Author: Patrick Palka Date: Sun Dec 19 12:10:16 2021 -0500 c++: local_specializations and recursive constrained fn [PR103714] Here during constraint checking for the inner call to A<0>::f<0>, substitution into the PARM_DECL d in the atomic constraint yields the wrong local specialization because local_specializations at this point is nonempty, and contains specializations for the caller A<0>::f<1>. This patch makes us call push_to_top_level during satisfaction, which'll temporarily clear local_specializations for us. PR c++/103714 gcc/cp/ChangeLog: * constraint.cc (satisfy_declaration_constraints): Do push_to_top_level and pop_from_top_level around the call to satisfy_normalized_constraints. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-uneval5.C: New test. (cherry picked from commit 30c286aa9377850c64aa35f5845a59d321a44be0) Diff: --- gcc/cp/constraint.cc | 4 ++++ gcc/testsuite/g++.dg/cpp2a/concepts-uneval5.C | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 76802964c70..5bdf6071a0f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3234,9 +3234,11 @@ satisfy_declaration_constraints (tree t, sat_info info) { if (!push_tinst_level (t)) return result; + push_to_top_level (); push_access_scope (t); result = satisfy_normalized_constraints (norm, args, info); pop_access_scope (t); + pop_from_top_level (); pop_tinst_level (); } @@ -3292,9 +3294,11 @@ satisfy_declaration_constraints (tree t, tree args, sat_info info) if (!push_tinst_level (t, args)) return result; tree pattern = DECL_TEMPLATE_RESULT (t); + push_to_top_level (); push_access_scope (pattern); result = satisfy_normalized_constraints (norm, args, info); pop_access_scope (pattern); + pop_from_top_level (); pop_tinst_level (); } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-uneval5.C b/gcc/testsuite/g++.dg/cpp2a/concepts-uneval5.C new file mode 100644 index 00000000000..a315a59b828 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-uneval5.C @@ -0,0 +1,17 @@ +// PR c++/103714 +// { dg-do compile { target c++20 } } + +template +struct A { + static const int i = I; + + template + void f(A d = {}) requires (d.i != i) { + f(); // { dg-error "no match" } + } +}; + +int main() { + A<0> a; + a.f<1>(); +}