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 r13-3641] c++: requires-expr and access checking [PR107179]
Date: Thu,  3 Nov 2022 19:36:00 +0000 (GMT)	[thread overview]
Message-ID: <20221103193600.78D1A3858D35@sourceware.org> (raw)

https://gcc.gnu.org/g:40c34beef620ed13c4113c893ed4335ccc1b8f92

commit r13-3641-g40c34beef620ed13c4113c893ed4335ccc1b8f92
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Nov 3 15:35:18 2022 -0400

    c++: requires-expr and access checking [PR107179]
    
    Like during satisfaction, we also need to avoid deferring access checks
    during substitution of a requires-expr because the outcome of an access
    check can determine the value of the requires-expr.  Otherwise (in
    deferred access checking contexts such as within a base-clause), the
    requires-expr may evaluate to the wrong result, and along the way a
    failed access check may leak out from it into a non-SFINAE context and
    cause a hard error (as in the below testcase).
    
            PR c++/107179
    
    gcc/cp/ChangeLog:
    
            * constraint.cc (tsubst_requires_expr): Make sure we're not
            deferring access checks.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts-requires31.C: New test.

Diff:
---
 gcc/cp/constraint.cc                             |  3 +++
 gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 5e6a3bcf059..f6ef078171a 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2252,6 +2252,9 @@ tsubst_requires_expr (tree t, tree args, sat_info info)
 {
   local_specialization_stack stack (lss_copy);
 
+  /* We need to check access during the substitution.  */
+  deferring_access_check_sentinel acs (dk_no_deferred);
+
   /* A requires-expression is an unevaluated context.  */
   cp_unevaluated u;
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C
new file mode 100644
index 00000000000..cd26b9ca077
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C
@@ -0,0 +1,15 @@
+// PR c++/107179
+// { dg-do compile { target c++20 } }
+
+template<bool B> struct bool_constant { static constexpr bool value = B; };
+
+template<typename T>
+  struct is_implicitly_default_constructible
+  : bool_constant<requires { T(); }>
+  { };
+
+struct X { private: X(); };
+struct Y { };
+
+static_assert( !is_implicitly_default_constructible<X>::value );
+static_assert(  is_implicitly_default_constructible<Y>::value );

                 reply	other threads:[~2022-11-03 19:36 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=20221103193600.78D1A3858D35@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).