【发布时间】: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 前端,对吗?