#### Example program #### template <typename> struct Outer { template <typename> class Inner { template <typename> friend class Inner; // All Inners should be friends public: template <typename T> void use_other_x(const Inner<T>& other) const { (void)other.x; // should be fine, we're all friends } private: // no error if private instead int x; }; }; int main() { Outer<int>::Inner<void> i1; Outer<int>::Inner<char> i2; i1.use_other_x(i2); } #### Error message #### prog.cc: In instantiation of 'void Outer< <template-parameter-1-1> >::Inner< <template-parameter-2-1> >::use_other_x(const Outer< <template-parameter-1-1> >::Inner<T>&) const [with T = char; <template-parameter-2-1> = void; <template-parameter-1-1> = int]': prog.cc:21:20: required from here prog.cc:11:20: error: 'int Outer<int>::Inner<char>::x' is protected within this context (void)other.x; ~~~~~~^ prog.cc:14:10: note: declared protected here int x; #### Notes #### No problems observed when using private: instead of protected:
ugh, very sorry, I copied the version with private: instead of protected. The example program should be: template <typename> struct Outer { template <typename> class Inner { template <typename> friend class Inner; // All Inners should be friends public: template <typename T> void use_other_x(const Inner<T>& other) const { (void)other.x; } protected: // no error if private instead int x; }; }; int main() { Outer<int>::Inner<void> i1; Outer<int>::Inner<char> i2; i1.use_other_x(i2); }
Compiled OK with r255779, started to ICE with r255780. The ICE seems to be fixed on gcc-8-branch but not on trunk.
(In reply to Jonathan Wakely from comment #2) > The ICE seems to be fixed on gcc-8-branch But is rejects-valid on the branch, instead of ice-on-valid-code on trunk.
working on head: https://wandbox.org/permlink/4dCLIfaIPWij81Vi
But not fixed on gcc-8-branch, so it should be kept open until the regression is fixed. Started to compile with r266875, which fixed: [PR86747] tsubst friend tpl ctxt before looking it up for dupes Possibly a dup of that one. It might get fixed when that is backported to gcc-8-branch.
GCC 8.3 has been released.
Still fails in 8.3.0 https://wandbox.org/permlink/69kAYkUWgFD5TTxs
Fixed for 8.4.