Namespace using declaration (bug in GCC/VS2010)?(使用声明的命名空间(GCC/VS2010 中的错误)?)
问题描述
命名空间 A{诠释我;}诠释主要(){使用 A::i;使用 A::i;}
VS2010 - 编译良好p>
gcc (ideone) - 编译良好p>
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 中的错误)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用声明的命名空间(GCC/VS2010 中的错误)?
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 静态初始化顺序失败 2022-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01