Skip to content

storage specifiers not respected on specialized template constexpr variables yet warning is thrown #114681

@jcelerier

Description

@jcelerier

Problem:

  • Given a template static constexpr variable in a .hpp, along with some specializations, clang, unlike MSVC and GCC emits non-weak symbols in all the TUs which causes duplicate symbol link errors.
template <typename T>
static const constexpr std::nullptr_t my_map = nullptr;

template <>
// gcc, msvc -> no duplicate symbol errors; all is fine
// clang 10 .. 19 -> link errors due to duplicate symbols
const constexpr int my_map<int> = 1;

template <>
// gcc, msvc -> fail to compile 
// clang 10 .. 18 -> ok
// clang 19 -> throws a warning here but still does not respect the original static storage class and behaves like previous clang versions in terms of emitted symbols.
static const constexpr int my_map<float> = 2;
  • If the specializations are marked static, then clang does not cause the duplicate symbol error anymore. But clang-19 now warns: "explicit specialization cannot have a storage class [-Wexplicit-specialization-storage-class]_" despite honoring it.

Full repro: https://gcc.godbolt.org/z/3cqnonv4Y

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions