Comeau vs g ++ [Another mistake]

Consider the following test 1 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 this well, while 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 right in this case? Como is one of the most standard compilers I know of. Is g ++ wrong?

(1) This is not a real life code.

+4
source share
1 answer

This is not true. face is private, so it is inaccessible from C. It would be legal if C were friendly to A and not face . face is a private member, so friend ing has no effect.

+6
source

Source: https://habr.com/ru/post/1386745/


All Articles