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

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

问题描述

namespace A{
   int i;
}

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

VS2010-可以正常编译

VS2010 - compiles fine

gcc(ideone)-可以正常编译

gcc (ideone) - compiles fine

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

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

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

$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.

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

So, is this a bug in GCC and VS2010?

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

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.

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

So, is this a bug in GCC and VS2010?

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

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 ...".

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

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天全站免登陆