Consider the following code:
class A {
class B {};
template <typename T>
friend class C;
};
template <typename T>
class C : A::B {};
int main() { C<int> c; }
It compiles fine with GCC and Clang but Visual C++ 2010 gives an error:
test.cc(11) : error C2248: 'A::B' : cannot access private class declared in class 'A'
Is it a bug in Visual C++ or am I missing something?
Both the 1998 standard and the 2011 standard contain essentially the same code as an example, in 14.5.3 #4 and 14.5.4 #3, respectively.
class X {
template<class T> friend struct A;
class Y { };
};
template<class T> struct A { X::Y ab; }; // OK
template<class T> struct A<T*> { X::Y ab; }; // OK
Apparently it's a bug.
Yes. That is most certainly a bug in the Visual C++ compiler.
Footnote: the GCC compiler compiles it fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With