使用声明的命名空间(GCC/VS2010 中的错误)? [英] Namespace using declaration (bug in GCC/VS2010)?

查看:111
本文介绍了使用声明的命名空间(GCC/VS2010 中的错误)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命名空间 A{诠释我;}诠释主要(){使用 A::i;使用 A::i;}

VS2010 - 编译良好

gcc (ideone) - 编译良好

Comeau - 给出错误ComeauTest.c",第 10 行:错误:i"已在当前范围内声明使用 A::i;"

<块引用>

$7.3.3/8 - 使用声明是声明,因此可以使用反复在哪里(并且只在哪里)允许多个声明."

上面的例子表明代码确实格式错误.

那么,这是 GCC 和 VS2010 中的错误吗?

编辑 2:

删除多个 using 指令,因为它与手头的查询无关.

解决方案

你参考的例子已知不一致.委员会还没有解决这个问题.

<块引用>

那么,这是 GCC 和 VS2010 中的错误吗?

我认为这不是 GCC/VS2010/Clang 或 Comeau 中的错误.它似乎是 C++ 标准中的一个错误.在这些情况下,编译作者必须决定什么是最可行的.如果您删除有问题的示例,则 3.3/4 声明该示例是有效的:给定单个声明区域中的一组声明,每个声明都指定相同的非限定名称,......它们都应引用相同的实体, 或全部引用函数和函数模板;或 ...".

问题出现了,正如链接问题中所讨论的那样,7.3.3/8 提到声明"时指的是什么,委员会没有就此达成共识.因此,在此之前 3.3/4 适用于 GCC/VS2010 和 Clang,而 Comeau 选择使用其他一些语义.

namespace A{
   int i;
}

int main(){
   using A::i;
   using A::i;
}

VS2010 - compiles fine

gcc (ideone) - compiles fine

Comeau - gives error ""ComeauTest.c", line 10: error: "i" has already been declared in the current scope using A::i;"

$7.3.3/8 - "A using-declaration is a declaration and can therefore be used repeatedly where (and only where) multiple declarations are allowed."

The example right there indicates that the code is indeed ill-formed.

So, is this a bug in GCC and VS2010?

EDIT 2:

Remove the multiple using directives as it was unrelated to the query on hand.

解决方案

The example you refer to is known to be inconsistent. The committee hasn't yet fixed this.

So, is this a bug in GCC and VS2010?

I don't think it's a bug in either of GCC/VS2010/Clang or Comeau. It appears to be a bug in the C++ Standard. In these cases, compile writers have to make up their mind on what is most viable. If you remove the example in question, then 3.3/4 states the example is valid: "Given a set of declarations in a single declarative region, each of which specifies the same unqualified name, ... they shall all refer to the same entity, or all refer to functions and function templates; or ...".

The question arises, as discussed in the linked issue, what 7.3.3/8 refers to when it says "declarations", which the committee didn't reach consensus about. And so, until then 3.3/4 applies for GCC/VS2010 and Clang, while Comeau chooses to use some other semantics.

这篇关于使用声明的命名空间(GCC/VS2010 中的错误)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆