[clang] [Clang][Sema] Diagnose variable template explicit specializations with storage-class-specifiers (PR #93873)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 04:53:44 PDT 2024


alexfh wrote:

It looks like the presence of `static` on template variable specializations makes difference in the namespace context: https://gcc.godbolt.org/z/b5ns1zhx6

Specifically, the specializations not marked `static` result in an exported variable. Thus, we have seemingly valid code that generates this diagnostic:
```
namespace A {
template <unsigned N, typename = std::enable_if_t<N >= 1 && N <= 64>>
static constexpr uint64_t kMaxUnsignedInt = 2 * kMaxUnsignedInt<N - 1> + 1;

template <>
static constexpr uint64_t kMaxUnsignedInt<1> = 1;
}
```

However, if we remove the `static` from the specialization, we're getting a potential ODR violation (considering this code can be in a header included into multiple translation units).

https://github.com/llvm/llvm-project/pull/93873


More information about the cfe-commits mailing list