【发布时间】:2014-08-05 08:52:13
【问题描述】:
我写了以下代码:
#include <iostream>
inline namespace M
{
int j=42;
}
int main(){ std::cout << j << "\n"; } //j is unqualified name here.
//Hence, unqualified name lookup rules will be applied.
//This implies that member of inline namespace shall not be considered.
//But it is not true
而且效果很好。但我预计该程序格式不正确。这是因为标准说(N3797,第 7.3.1/7 节):
最后,通过显式在封闭的命名空间中查找名称 资格(3.4.3.2)将包括内联命名空间的成员 由 using 指令引入,即使有声明 该名称位于封闭的命名空间中。
第 3.4.1/6 节也没有说明在非限定名称查找中涉及内联命名空间:
在函数的定义中使用的名称 declarator-id 28 是命名空间 N 的成员(其中,仅用于 说明的目的,N 可以代表全局范围)应为 在使用它之前在使用它的块中或在其中之一中声明 它的封闭块(6.3)或,应在其使用前声明 命名空间 N 或者,如果 N 是嵌套命名空间,则应在之前声明 它在 N 的封闭命名空间之一中使用。
这是 g++ 错误还是我理解错误的规则?
【问题讨论】:
标签: c++ c++11 namespaces inline language-lawyer