https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119824
Bug ID: 119824
Summary: initialization of a static member variable with type
auto or decltype(auto) is not accepted
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: heiko at hexco dot de
Target Milestone: ---
I experimented with forms of initialization for static member variables and
found different results with different compilers.
Now I am not sure if my code is really valid C++17...
I compiled this with GCC trunk with -Wall -Wextra -O2 --std=c++17
========================
struct z {
static unsigned a;
static unsigned b;
static inline auto c{3U};
static const auto d{4U};
};
decltype(auto) z::a{1U};
auto z::b{2U};
int main() { return 0; }
========================
EDG, ICX and Clang accept it, while MSVC and GCC don't, claiming type
conflicts.
Output:
<source>:7:16: error: conflicting declaration 'decltype(auto) z::a'
7 | decltype(auto) z::a{1U};
| ^
<source>:2:19: note: previous declaration as 'unsigned int z::a'
2 | static unsigned a;
| ^
<source>:8:6: error: conflicting declaration 'auto z::b'
8 | auto z::b{2U};
| ^
<source>:3:19: note: previous declaration as 'unsigned int z::b'
3 | static unsigned b;
| ^
Compiler returned: 1
For a comparison see also https://godbolt.org/z/7f89xbzPa
Thanks!