"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does GCC Fail to Compile Explicit Specialization in Non-Namespace Scope?

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

Published on 2024-12-21
Browse:673

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3