我阅读了有关命名空间定义的部分.N3797的第7.3.1条规定:
只有先前在该命名空间的原始命名空间定义上使用了inline关键字,才可以在扩展命名空间定义上使用该关键字.
请考虑以下代码段:
namespace M
{
int h;
}
inline namespace M
{
int j = 6;
}
Run Code Online (Sandbox Code Playgroud)
它使用-std=c++11和不使用该选项编译成功.你能解释一下这种行为吗?这是一个g++错误吗?
Vour对标准的引用是明确的:这是不允许的.
使用Clang ++我得到关于此的非常明确的错误消息:
Test0614-1.cpp:17:18: error: non-inline namespace cannot be reopened as inline
inline namespace M
^
Test0614-1.cpp:12:11: note: previous definition is here
namespace M
^
Run Code Online (Sandbox Code Playgroud)
所以它肯定是g ++中的一个错误.顺便提一下,这里有报道:https://gcc.gnu.org/bugzilla/show_bug.cgi?id = 53402
编译器接受标准的先前版本的内联命名空间并且至少没有警告这一事实似乎是一个问题.这已经在2010年被报告为bug,应该已经修复:https: //gcc.gnu.org/bugzilla/show_bug.cgi?id = 43824