When a class is declared A
as a friend of the class B
, but A
is defined inside the anonymous namespace and B
externally, 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>{});
}
A
and 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 errorA
is not a template, but B
a template: Intel icc 18: no error, gcc 7.2: error :, 'void B<T>::bar() const [with T = int]' is protected within this context
clang 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.
, ? ?