Consider the following test1 code
struct A {
private:
class face;
friend class face;
};
struct A::face {};
template <typename _CharT>
struct C : public A::face
{};
int main()
{
C<int> x;
}
Is this code well formed? I tested it under g++ and comeau. g++ compiles it fine whereas comeau gives the following error message (which I think is correct)
"ComeauTest.c", line 12: error: class "A::face" (declared at line 9) is inaccessible
struct C : public A::face
^
detected during instantiation of class "C<_CharT> [with _CharT=int]"
at line 17
Which compiler is correct in this case? Comeau is one of the most standard conforming compiler that I know of. Is g++ wrong again?
(1) This is not a real life code.
It’s incorrect.
faceis private, so it’s not accessible from C. This would only be legal if C had been friended from A, notface.faceis a private member, and sofriending it has no effect.