匿名结构中声明的函数的名称解析
Name resolution for function declared in anonymous struct
f
定义的参数列表中的以下代码中的 A
、B
、C
的名称解析应该起作用吗?
namespace ns
{
struct A {};
struct S
{
struct B {};
struct
{
struct C {};
void f(A, B, C);
} x;
};
}
#include <type_traits>
void std::type_identity_t<decltype(ns::S::x)>::f(A, B, C) {}
int main()
{
}
实际上 works 最近 clang
。
[basic.lookup.unqual]/8 For the members of a class X
, a name used ... in the definition of a class member outside of the definition of X
, following the member's declarator-id(24), shall be declared in one of the following ways:
...
(8.2) — shall be a member of class X
..., or
(8.3) — if X
is a nested class of class Y
(11.4.10), shall be a member of Y
,... or
...
(8.5) — if X
is a member of namespace N
, or is a nested class of a class that is a member of N
, ... before the use of the name, in namespace N
or in one of N
's enclosing namespaces.
Footnote 24) That is, an unqualified name that occurs, for instance, in a type in the parameter-declaration-clause or in the noexcept-specifier.
这里X
是decltype(ns::S::x)
,Y
是S
,N
是ns
。因此,通过 (8.5) 找到 A
,通过 (8.3) 找到 B
,通过 (8.2) 找到 C
。
f
定义的参数列表中的以下代码中的 A
、B
、C
的名称解析应该起作用吗?
namespace ns
{
struct A {};
struct S
{
struct B {};
struct
{
struct C {};
void f(A, B, C);
} x;
};
}
#include <type_traits>
void std::type_identity_t<decltype(ns::S::x)>::f(A, B, C) {}
int main()
{
}
实际上 works 最近 clang
。
[basic.lookup.unqual]/8 For the members of a class
X
, a name used ... in the definition of a class member outside of the definition ofX
, following the member's declarator-id(24), shall be declared in one of the following ways:
...
(8.2) — shall be a member of classX
..., or
(8.3) — ifX
is a nested class of classY
(11.4.10), shall be a member ofY
,... or
...
(8.5) — ifX
is a member of namespaceN
, or is a nested class of a class that is a member ofN
, ... before the use of the name, in namespaceN
or in one ofN
's enclosing namespaces.Footnote 24) That is, an unqualified name that occurs, for instance, in a type in the parameter-declaration-clause or in the noexcept-specifier.
这里X
是decltype(ns::S::x)
,Y
是S
,N
是ns
。因此,通过 (8.5) 找到 A
,通过 (8.3) 找到 B
,通过 (8.2) 找到 C
。