Home  >  Article  >  Backend Development  >  Why Does GCC Fail to Compile Explicit Specialization in Non-Namespace Scope?

Why Does GCC Fail to Compile Explicit Specialization in Non-Namespace Scope?

Susan Sarandon
Susan SarandonOriginal
2024-11-16 05:40:03134browse

Why Does GCC Fail to Compile Explicit Specialization in Non-Namespace Scope?

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:

  • Class definitions (12.2)
  • Member functions (17.6.2)
  • Inline namespaces (10.3.1.2)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn