https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126514
Bug ID: 126514
Summary: GCC rejects valid out-of-class static data member
definition with auto
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: attackerj1113 at gmail dot com
Target Milestone: ---
The following code is rejected by GCC, but accepted by Clang, MSVC, and EDG:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct S
{
static int b;
};
auto S::b = 4;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://godbolt.org/z/vYjv3q93e
Output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:6: error: conflicting declaration 'auto S::b'
6 | auto S::b = 4;
| ^
<source>:3:14: note: previous declaration as 'int S::b'
3 | static int b;
| ^
Compiler returned: 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GCC rejects auto S::b = 4; when S::b was previously declared as static int b;.
Replacing auto with int is accepted.
As I understand it, auto here is deduced as int, so the two declarations would
appear to be consistent — though I may be missing something, and would
appreciate clarification.