[Bug c++/86747] [8/9 Regression] rejects-valid with redundant friend declaration
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86747 François-R Boyer changed: What|Removed |Added CC||Francois-R.Boyer at PolyMtl dot ca --- Comment #3 from François-R Boyer --- I'm not sure if this bug is related or if I should post it as a separate bug report. I have the same error messages, with a friend class, but in my case it is not redundant, and happens in a much more complicated case. Here is the code: template struct A { template class> struct B { template class> friend struct B; }; }; template struct C { }; A::B b; The above compiles on latest MSVC, clang, and most other compilers on godbolt, including g++ 7.3. The error with g++ 8.1, 8.2 and 9.0.0 20181007 on godbolt is: : In instantiation of 'struct A::B': :9:14: required from here :2:32: error: template parameter 'template template class' 2 | template class> struct B { |^ :3:57: error: redeclared here as 'template class' 3 | template class> friend struct B; | ^ Note that if struct A is not a template, of if struct B has a simple type parameter instead of a template template, it compiles.
[Bug c++/87571] New: [8/9 Regression] ICE in friend_accessible_p, accessing protected member of template friend inside template class
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87571 Bug ID: 87571 Summary: [8/9 Regression] ICE in friend_accessible_p, accessing protected member of template friend inside template class Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: Francois-R.Boyer at PolyMtl dot ca Target Milestone: --- The following code fails to compile with g++ 8.1, 8.2 and 9.0.0 20181007 on godbolt, but compiles with g++ 7.3, clang, MSVC, etc.: template struct A { template struct B { template friend class B; protected: int protected_member_; public: template int method(const B& other) const { return other.protected_member_; } }; }; int main() { A::B a; A::B b; a.method(b); } The error message is: : In instantiation of 'int A< >::B< >::method(const A< >::B&) const [with T = char; = int; = int]': :16:13: required from here :8:20: internal compiler error: in friend_accessible_p, at cp/search.c:719 8 | return other.protected_member_; | ~~^ Note that it compiles if we change any of these: - the member is private instead of protected, - struct A is not a template, or - we explicitly 'friend class B;' instead or in addition of the template friend.