https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125674
Bug ID: 125674
Summary: ICE in cxx_eval_constant_expression with invalid
bit-field width in template
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-invalid-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: attackerj1113 at gmail dot com
Target Milestone: ---
GCC crashes when handling an invalid bit-field width expression in a class
template.
https://godbolt.org/z/rM5can3PY
Example 1, with CTAD, triggers the ICE starting from GCC 16.1 (assertions
build), adding -std=c++17 prevents the crash:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<class T>
struct A {
int f();
T i : f;
};
A a{0};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example 2, no CTAD, triggers the ICE since at least GCC 10.5 (assertions
build):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<class T>
struct A {
int f();
T i : f;
};
A<int> a{0};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Removing the template avoids the crashes.
The issue appears to be that an invalid bit-field width expression is not
rejected during semantic analysis and is instead passed to constant expression
evaluation (cxx_eval_constant_expression), leading to an ICE.
CTAD is not the root cause, but in newer GCC versions it causes earlier or
different instantiation paths, exposing the same underlying bug.