Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comeau vs g++ [Yet another bug]

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.

like image 580
Prasoon Saurav Avatar asked Dec 16 '11 17:12

Prasoon Saurav


1 Answers

It's incorrect. face is private, so it's not accessible from C. This would only be legal if C had been friended from A, not face. face is a private member, and so friending it has no effect.

like image 98
Puppy Avatar answered Sep 29 '22 13:09

Puppy