You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structB { friendstructA; private: B(int); };
template<classT> intf(T = 0);
structA { A() { int i = f<B>(); } };
Per http://eel.is/c++draft/temp.inst#12.sentence-1 access control should be the same as for a function template specialization adjacent to f; the friendship of A is irrelevant. MSVC and gcc get this right, although gcc weirdly accepts-invalid if the ctor is B() and the default argument initializer is {}.
Worse, clang correctly rejects if the caller is not a friend:
structB { friendstructA; private: B(int); };
template<classT> intf(T = 0);
int i = f<B>(); // error: calling a private constructor of class 'B'
but if the friend call is moved first it accepts, indicating that the instantiated default argument has been remembered, which would be fine if it didn't use A's access control.
structB { friendstructA; private: B(int); };
template<classT> intf(T = 0);
structA { A() { int i = f<B>(); } };
int i = f<B>();