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.
{
push_to_top_level ();
push_nested_class (ctx);
+ push_deferring_access_checks (dk_no_deferred);
pushed = true;
}
if (pushed)
{
+ pop_deferring_access_checks ();
pop_nested_class ();
pop_from_top_level ();
}
--- /dev/null
+// 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;
+}