gpt4 book ai didi

c++ - 内联命名空间和不明确的声明

转载 作者:太空狗 更新时间:2023-10-29 20:39:38 25 4
gpt4 key购买 nike

我想知道这是否被允许:

namespace A {
inline namespace B {
int a;
}
int a;
}

void foo() {
A::a = 0; // clang 3.4 compiles, but gcc doesn't
}

标准说,那

Finally, looking up a name in the enclosing namespace via explicit qualification (3.4.3.2) will include members of the inline namespace brought in by the using-directive even if there are declarations of that name in the enclosing namespace.

但是我无法得到它。

最佳答案

看起来这是一个 pre clang 3.5 bug关于这个 812 有两个缺陷报告和 861 .该决议在 861 中,并将以下内容添加到 3.4.3.2 [namespace.qual](强调我的前进):

For a namespace X and name m, the namespace-qualified lookup set S(X,m) is defined as follows: Let S'(X,m) be the set of all declarations of m in X and the inline namespace set of X (7.3.1 [namespace.def]). If S'(X,m) is not empty, S(X,m) is S'(X,m); otherwise, S(X,m) is the union of S(Ni,m) for all non-inline namespaces Ni nominated by using-directives in X and its inline namespace set.

以及相关的补充:

if S(X,m) is the empty set, the program is ill-formed. Otherwise, if S(X,m) has exactly one member, or if the context of the reference is a using-declaration (7.3.3 [namespace.udecl]), S(X,m) is the required set of declarations of m. Otherwise if the use of m is not one that allows a unique declaration to be chosen from S(X,m), the program is ill-formed.

看起来更改是在 C++11 之前添加的,此文本存在于 N3337 中.

关于c++ - 内联命名空间和不明确的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27252466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com