https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122164
Bug ID: 122164
Summary: Type deduction with `auto` does not seem to work
through static member variable initialization
Product: gcc
Version: 16.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: ---
Consider the following code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct A {
static int x;
static int y;
int foo();
};
int temp = 0;
decltype(temp) A::y = 0; //ok
auto A::x = temp; //rejected
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is rejected by GCC for type mismatch when trying to initialize `A::x` with
`auto A::x`, although the type of `A::x` here can be easily deduced to `int`,
which is identical to the type of `A::x` in the previous declaration of `struct
A`. Note that both LLVM and EDG accept the code, while MSVC also rejects it.
See godbolt: https://godbolt.org/z/1MqeavEcr
Member function declaration with auto return type is always rejected though:
https://godbolt.org/z/TaTqchGdE