命名空间使用声明(GCC/VS2010 中的错误)?
namespace A{
int i;
}
int main(){
using A::i;
using A::i;
}
VS2010 - 编译良好的
gcc (ideone) - 编译良好的
Comeau - 给出错误“”ComeauTest.c”,第 10 行:错误:“i”已在当前作用域中声明 使用 A::i;”
$7.3.3/8 - “使用声明是 声明,因此可以使用 重复在哪里(并且仅在哪里) 允许多个声明。”
那里的示例表明代码确实格式错误。
那么,这是 GCC 和 VS2010 中的错误吗?
编辑 2:
删除多个 using 指令
,因为它不相关到手头的查询。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您引用的示例已知不一致。委员会尚未解决这个问题。
我不认为这是 GCC/VS2010/Clang 或 Comeau 中的错误。这似乎是 C++ 标准中的一个错误。在这些情况下,编译者必须决定什么是最可行的。如果删除有问题的示例,则 3.3/4 声明该示例是有效的:“给定单个声明区域中的一组声明,每个声明都指定相同的非限定名称,......它们都应引用相同的实体,或全部引用函数和函数模板;或...”。
正如相关问题中所讨论的,问题出现了,7.3.3/8 当它提到“声明”时指的是什么,委员会并未就此达成共识。因此,在此之前 3.3/4 适用于 GCC/VS2010 和 Clang,而 Comeau 选择使用其他一些语义。
The example you refer to is known to be inconsistent. The committee hasn't yet fixed this.
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.
是的你是对的。这确实是 g++、MSVC++ 和 Clang 中的一个 bug。科莫说得对。
正如你所说的
7.3.3/8
所说。还给出了以下代码片段。
同样,您的代码也是格式错误的。
Yes you are right. This is indeed a bug in g++, MSVC++ and Clang. Comeau has got it correct.
As you said
7.3.3/8
saysThe following code snippet is also given.
Similarly your code is ill-formed too.