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 r14-8981] c++: synthesized_method_walk context independence [PR113908]
Date: Wed, 14 Feb 2024 15:21:04 +0000 (GMT)	[thread overview]
Message-ID: <20240214152105.1E90C385801F@sourceware.org> (raw)

https://gcc.gnu.org/g:9bc6b23d11697545e8a951ccd60691b1e58b98c2

commit r14-8981-g9bc6b23d11697545e8a951ccd60691b1e58b98c2
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Feb 14 10:20:31 2024 -0500

    c++: synthesized_method_walk context independence [PR113908]
    
    In the second testcase below, during ahead of time checking of the
    non-dependent new-expr we synthesize B's copy ctor, which we expect to
    get defined as deleted since A's copy ctor is inaccessible.  But during
    access checking thereof, enforce_access incorrectly decides to defer it
    since we're in a template context according to current_template_parms
    (before r14-557 it checked processing_template_decl which got cleared
    from implicitly_declare_fn), which leads to the access check leaking out
    to the template context that triggered the synthesization, and B's copy
    ctor getting declared as non-deleted.
    
    This patch fixes this by using maybe_push_to_top_level to clear the
    context (including current_template_parms) before proceeding with the
    synthesization.  We could do this from implicitly_declare_fn, but it's
    better to do it more generally from synthesized_method_walk for sake of
    its other callers.
    
    This turns out to fix PR113332 as well: there the lambda context
    triggering synthesization was causing maybe_dummy_object to misbehave,
    but now synthesization is sufficiently context-independent.
    
            PR c++/113908
            PR c++/113332
    
    gcc/cp/ChangeLog:
    
            * method.cc (synthesized_method_walk): Use maybe_push_to_top_level.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/lambda/lambda-nsdmi11.C: New test.
            * g++.dg/template/non-dependent31.C: New test.
    
    Reviewed-by: Jason Merrill <jason@redhat.com>

Diff:
---
 gcc/cp/method.cc                                   |  2 ++
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi11.C | 20 ++++++++++++++++++++
 gcc/testsuite/g++.dg/template/non-dependent31.C    | 18 ++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 957496d3e180..98c10e6a8b5b 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -2760,6 +2760,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
 	return;
     }
 
+  bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype));
   ++cp_unevaluated_operand;
   ++c_inhibit_evaluation_warnings;
   push_deferring_access_checks (dk_no_deferred);
@@ -2857,6 +2858,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
   pop_deferring_access_checks ();
   --cp_unevaluated_operand;
   --c_inhibit_evaluation_warnings;
+  maybe_pop_from_top_level (push_to_top);
 }
 
 /* DECL is a defaulted function whose exception specification is now
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi11.C
new file mode 100644
index 000000000000..246654c5b502
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi11.C
@@ -0,0 +1,20 @@
+// PR c++/113332
+// { dg-do compile { target c++11 } }
+
+struct tuple {
+  template<class _Tp>
+  static constexpr bool __is_implicitly_default_constructible() { return true; }
+
+  template<class _Tp = void,
+           bool = __is_implicitly_default_constructible<_Tp>()>
+  tuple();
+};
+
+struct DBusStruct {
+private:
+  tuple data_;
+};
+
+struct IBusService {
+  int m = [] { DBusStruct{}; return 42; }();
+};
diff --git a/gcc/testsuite/g++.dg/template/non-dependent31.C b/gcc/testsuite/g++.dg/template/non-dependent31.C
new file mode 100644
index 000000000000..3fa68f40fe11
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent31.C
@@ -0,0 +1,18 @@
+// PR c++/113908
+// { dg-do compile { target c++11 } }
+
+struct A {
+  A();
+private:
+  A(const A&);
+};
+
+struct B {
+  A a;
+
+  template<class T>
+  static void f() { new B(); }
+};
+
+template void B::f<int>();
+static_assert(!__is_constructible(B, const B&), "");

                 reply	other threads:[~2024-02-14 15:21 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=20240214152105.1E90C385801F@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).