鉴于§3.5/ 4中的以下语句(强调我的)和§7.3.1.1/ 1中的注释[94],我想在一个具有外部链接的未命名命名空间中声明的实体的一个单独示例.
§3.5/ 4
An unnamed namespace or a namespace declared directly or indirectly
within an unnamed namespace has internal linkage. All other namespaces
have external linkage. A name having namespace scope that has not been
given internal linkage above has the same linkage as the enclosing
namespace if it is the name of
- a variable; or
- a function; or
- a named class (Clause 9),or an unnamed class defined in a typedef declaration in which the class has the typedef name for linkage
purposes (7.1.3); or- a named enumeration (7.2),or an unnamed enumeration defined in a typedef declaration in which the enumeration has the typedef name for
linkage purposes (7.1.3); or- an enumerator belonging to an enumeration with linkage; or
- a template.
关于§7.3.1.1/ 1的注释[94]:
Although entities in an unnamed namespace might have external linkage,
they are effectively qualified by a name unique to their translation
unit and therefore can never be seen from any other translation unit.
解决方法
您正在查看标准中的缺陷.
在2010年11月(CWG issue 1113)的C 11标准化过程中,使未命名的命名空间成员具有内部链接的更改发生得相当晚.因此,标准中的许多地方需要改变,但事实并非如此.其中一个是你引用的脚注.
CWG issue 1603,目前处于“就绪”状态(阅读:该决议很可能在下次委员会会议上通过),将修复此问题以及与未命名的命名空间成员提供内部链接相关的许多其他问题.