尝试通过 using-declaration 定义命名空间成员
Trying to define namespace member via using-declaration
考虑以下程序。是否符合c++标准(需要参考标准的相关部分):
namespace X { extern int i; }
namespace N { using X::i; }
int N::i = 1;
int main() {}
对于不同的编译器,我得到了不同的结果。我想弄清楚我应该为哪个编译器提交错误报告:
Clang:给出以下编译器错误:命名空间 'N'
中没有名为 'i' 的成员
GCC 和 Visual C++ 编译它没有错误。
为了进行比较,以下给出了所有三个编译器的编译器错误:
namespace X { void f(); }
namespace N { using X::f; }
void N::f() {};
int main() {}
当前工作草案 N4527,[8.3p1]:
[...] When the declarator-id is qualified, the declaration shall refer to a
previously declared member of the class or namespace to which the
qualifier refers (or, in the case of a namespace, of an element of the
inline namespace set of that namespace (7.3.1)) or to a specialization
thereof; the member shall not merely have been introduced by a
using-declaration in the scope of the class or namespace nominated by
the nested-name-specifier of the declarator-id. [...]
所以,肯定是病式的; GCC 和 MSVC 是错误的。
考虑以下程序。是否符合c++标准(需要参考标准的相关部分):
namespace X { extern int i; }
namespace N { using X::i; }
int N::i = 1;
int main() {}
对于不同的编译器,我得到了不同的结果。我想弄清楚我应该为哪个编译器提交错误报告:
Clang:给出以下编译器错误:命名空间 'N'
中没有名为 'i' 的成员
GCC 和 Visual C++ 编译它没有错误。
为了进行比较,以下给出了所有三个编译器的编译器错误:
namespace X { void f(); }
namespace N { using X::f; }
void N::f() {};
int main() {}
当前工作草案 N4527,[8.3p1]:
[...] When the declarator-id is qualified, the declaration shall refer to a previously declared member of the class or namespace to which the qualifier refers (or, in the case of a namespace, of an element of the inline namespace set of that namespace (7.3.1)) or to a specialization thereof; the member shall not merely have been introduced by a using-declaration in the scope of the class or namespace nominated by the nested-name-specifier of the declarator-id. [...]
所以,肯定是病式的; GCC 和 MSVC 是错误的。