This is a spin out of a problem mentioned in PR13092. The following testcase shouldn't compile because only fr<int> is friend of class D. But we are accessing protected members from fr<char>. GCC 3.4, 3.5 fail to diagnose it. Earlier GCC don't handle this properly (checking access while parsing the template fr<T> which is too early.) So it's not a regression. // Two-phase name lookup for address of member: // Protected member access class B { protected: int i; // { dg-error "protected" } }; template <class T> void fr (); class D2 : public B { friend void fr<int> (); }; template<int B::*> struct X {}; template <class T> void fr () { X<&B::i> x1; // { dg-error "context" } X<&D2::i> x2; // { dg-error "context" } } template void fr<char>(); // { dg-error "instantiated" }
Confirmed. W.
Got it. The target for this fix is GCC 4.1.
May be fixed together with PR19311.
This is a stage 2 project. Likely to be fixed in a month or two.
Patch using new approach for 4.1: http://gcc.gnu.org/ml/gcc-patches/2005-05/msg01992.html (Note this is part 4 in a series, earlier parts are also required)
Patch withdrawn due to overlooking default function argument and default template argument. No nice solution is found yet.
*** Bug 33934 has been marked as a duplicate of this bug. ***
*** Bug 24118 has been marked as a duplicate of this bug. ***
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:330cc29c06306ebf7bd3b2d37704cc69944923ff commit r12-69-g330cc29c06306ebf7bd3b2d37704cc69944923ff Author: Patrick Palka <ppalka@redhat.com> Date: Thu Apr 22 13:32:40 2021 -0400 c++: Add testcase for already fixed PR [PR16617] We correctly diagnose the invalid access since r11-1350. gcc/testsuite/ChangeLog: PR c++/16617 * g++.dg/template/access36.C: New test.
Fixed for GCC 11 by the patch for PR41437.