When a class is declared Aas a friend of the class B, but Ais defined inside the anonymous namespace and Bexternally, some compilers produce a "protected member is not available" error, while others do not produce any error or warning. The situation changes if either A, or B, or both are patterns:
namespace {
template <class T>
struct A {
template <class BB>
void foo(BB const& b) { b.bar(); }
};
}
template <class T>
class B {
template <class> friend struct A;
protected:
void bar() const {}
};
int main() {
A<int> a;
a.foo(B<int>{});
}
Aand B- both patterns. Then Intel icc 18: error #308: function "B<T>::bar [with T=int]" is inaccessible , gcc 7.2: no error, clang 5.0: no errorAis not a template, but Ba template: Intel icc 18: no error, gcc 7.2: error :, 'void B<T>::bar() const [with T = int]' is protected within this contextclang 5: no errorA , B : Intel icc 18: #308, gcc 7.2: , clang 5: no errorA, B : Intel icc 18: , gcc 7.2: , clang 5: no errorA, B ( 4.), A B: Intel icc 18: #308, gcc 7.2: , clang 5: : 'bar' is a protected member of 'B'A B ( 1.), A B: Intel icc 18: #308, gcc 7.2: , clang 5:
. : https://godbolt.org/g/6Zdr3c https://godbolt.org/g/BRqf78 6.
, ? ?