【问题标题】:Comeau vs g++ [Yet another bug]Comeau vs g++ [又一个错误]
【发布时间】:2011-12-16 17:45:14
【问题描述】:

考虑以下测试1代码

struct A {
 private:         
     class face;
     friend class face; 
};

struct A::face {};    

template <typename _CharT>
struct C : public A::face
{};

int main()
{
  C<int> x;
}

这段代码格式正确吗?我在 g++ 和 comeau 下对其进行了测试。 g++ 编译得很好,而 comeau 给出以下错误消息(我认为是正确的)

"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

在这种情况下哪个编译器是正确的? Comeau 是我所知道的最符合标准的编译器之一。 g++又错了吗?

(1) 这不是真实的代码。

【问题讨论】:

  • clang++ 3.0 也会编译它,只是它指出它在一个地方是 class face 而在另一个地方是 struct face
  • @Cubbi :是的,也尝试过 clang。编译错误。
  • Intel 11.1 有一个明显的诊断test.cc(10): warning #525: class "A::face" (declared at line 7) is an inaccessible type (allowed for cfront compatibility) Sun 和微软也拒绝编译。
  • Comeau 和 Intel 都使用相同的 EDG 前端,对吗?

标签: c++ private comeau


【解决方案1】:

这是不正确的。 face 是私有的,因此不能从 C 访问。这只有在 C 是 A 的朋友时才合法,而不是 faceface 是私有成员,因此 friending 无效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-19
    • 2012-10-07
    相关资源
    最近更新 更多