https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116121
Bug ID: 116121
Summary: GCC rejects valid program involving explicit
specialization of static data member without
specializing the class template itself
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
The following valid program afaik is rejected by gcc and msvc but accepted by
clang: https://godbolt.org/z/PTY1a6cTP
```
#include <iostream>
#include <iomanip>
//wrapper
template<typename T>
struct Wrapper
{
inline static T value{};
};
template<> int Wrapper<int>::value = 42; //clang:OK, gcc:Nope,
MSVC:Nope
template<> double Wrapper<double>::value = 3.14; //clang:OK, gcc:Nope,
MSVC:Nope
int main()
{
}
```
GCC says:
```
<source>:11:30: error: duplicate initialization of 'Wrapper<int>::value'
11 | template<> int Wrapper<int>::value = 42;
| ^~~~~
<source>:12:36: error: duplicate initialization of 'Wrapper<double>::value'
12 | template<> double Wrapper<double>::value = 3.14;
|
```