Explicit Specialization in Non-Namespace Scope
The given code fails to compile in GCC despite compiling successfully in Clang. According to the C standard ([temp.expl.spec]), explicit specializations can be declared in any scope where the corresponding primary template could be defined.
This behavior appears to be a bug in GCC. According to CWG 727, the rule in [temp.expl.spec] regarding explicit specialization has been modified to allow such declarations in any relevant scope.
Scope of Explicit Specialization
The original standard stated that explicit specialization should be declared in a namespace enclosing the specialized template. However, the current standard permits explicit specialization in any scope where the primary template can be defined:
GCC's failure to adhere to this updated rule constitutes a bug. The issue has been identified as Bug 85282 and is currently tracked by the GCC development team.
The above is the detailed content of Why Does GCC Fail to Compile Explicit Specialization in Non-Namespace Scope?. For more information, please follow other related articles on the PHP Chinese website!