public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-10164] c++: access checking in aggregate initialization [PR96673]
@ 2022-05-13 17:41 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-05-13 17:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e0cc2713a4076edd4f20b80b0fe217c9ab1676b2

commit r9-10164-ge0cc2713a4076edd4f20b80b0fe217c9ab1676b2
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Apr 6 15:13:02 2021 -0400

    c++: access checking in aggregate initialization [PR96673]
    
    We were deferring access checks while parsing B<int>{}, didn't adjust that
    when we went to instantiate the default member initializer for B::c,
    deferred access checking for C::C, and then checked it after parsing
    B<int>{}, back in the main() context which has no access.  We need to do the
    access checks in the class context of the DMI.
    
    I tried fixing this in push_to/pop_from_top_level, but that caused several
    regressions.
    
    gcc/cp/ChangeLog:
    
            PR c++/96673
            * init.c (get_nsdmi): Don't defer access checking.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/96673
            * g++.dg/cpp1y/nsdmi-aggr13.C: New test.

Diff:
---
 gcc/cp/init.c                             |  2 ++
 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr13.C | 33 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 44f767481c4..dc9145892c4 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -591,6 +591,7 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
 	    {
 	      push_to_top_level ();
 	      push_nested_class (ctx);
+	      push_deferring_access_checks (dk_no_deferred);
 	      pushed = true;
 	    }
 
@@ -620,6 +621,7 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
 
 	  if (pushed)
 	    {
+	      pop_deferring_access_checks ();
 	      pop_nested_class ();
 	      pop_from_top_level ();
 	    }
diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr13.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr13.C
new file mode 100644
index 00000000000..845e26ff593
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr13.C
@@ -0,0 +1,33 @@
+// PR c++/96673
+// { dg-do compile { target c++11 } }
+
+template <class T>
+class A {};
+
+template <class T>
+class B;
+
+template <class T>
+class C {
+    private:
+
+    friend class B<T>;
+
+    explicit C(A<T>&) {};
+};
+
+
+template <class T>
+class B {
+    public:
+    B() = default;
+    //B() {};       // << This implementation of the constructor makes it work
+
+    A<T> a = {};
+    C<T> c = C<T>{a};
+};
+
+int main() {
+    auto b = B<int>{};
+    auto &c = b.c;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-13 17:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 17:41 [gcc r9-10164] c++: access checking in aggregate initialization [PR96673] Jason Merrill

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).