https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118543
Bug ID: 118543
Summary: Previous forward declaration of enum causes early
instantiation of later definition
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: andre.brand at mailbox dot org
Target Milestone: ---
See here on Compiler-Explorer: https://godbolt.org/z/PshPT968x
template <typename T>
struct S {
static constexpr T f(int) { return 0; };
// remove the opaque declaration and it will work
enum class E : T;
static constexpr T f(char) { return 1; };
enum class E : T { X = f(T{}) };
};
static_assert((int)S<char>::E::X == 1);
This causes:
static assertion failed
13 | static_assert((int)S<char>::E::X == 1);
| ~~~~~~~~~~~~~~~~~~~^~~~
<source>:13:34: note: the comparison reduces to '(0 == 1)'
GCC seems to consider the overload set of f at the first declaration.
This is not the case for static constexpr data members of a nested class.