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-6063] c++: local_specializations and recursive constrained fn [PR103714]
Date: Sun, 19 Dec 2021 17:10:31 +0000 (GMT)	[thread overview]
Message-ID: <20211219171031.9DC993858400@sourceware.org> (raw)

https://gcc.gnu.org/g:30c286aa9377850c64aa35f5845a59d321a44be0

commit r12-6063-g30c286aa9377850c64aa35f5845a59d321a44be0
Author: Patrick Palka <ppalka@redhat.com>
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.

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 8386a7dd411..96fa6a75b7a 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3177,9 +3177,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 ();
     }
 
@@ -3235,9 +3237,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<int I>
+struct A {
+  static const int i = I;
+
+  template<int J>
+  void f(A<J> d = {}) requires (d.i != i) {
+    f<I>(); // { dg-error "no match" }
+  }
+};
+
+int main() {
+  A<0> a;
+  a.f<1>();
+}


                 reply	other threads:[~2021-12-19 17:10 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=20211219171031.9DC993858400@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: 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).