[Bug c++/125674] [13/14/15 Regression] ICE in cxx_eval_constant_expression with invalid bit-field width in template
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 16 09:11:55 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125674
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:a11b76ce4db284c4071901a3fe283be655bc74b5
commit r14-12743-ga11b76ce4db284c4071901a3fe283be655bc74b5
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Jun 12 22:43:06 2026 +0200
c++: Diagnose invalid type of bitfield widths in templates [PR125674]
As the first testcase shows, outside of templates or when
the bitfield width is not type dependent, we diagnose it
in grokbitfield:
if (width != error_mark_node)
{
/* The width must be an integer type. */
if (!type_dependent_expression_p (width)
&& !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
error ("width of bit-field %qD has non-integral type %qT", value,
TREE_TYPE (width));
else if (!check_for_bare_parameter_packs (width))
{
/* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
check_bitfield_decl picks it from there later and sets
DECL_SIZE
accordingly. */
DECL_BIT_FIELD_REPRESENTATIVE (value) = width;
SET_DECL_C_BIT_FIELD (value);
}
}
Later on in check_bitfield_decl we verify it is a constant expression,
folded into INTEGER_CST, non-negative etc.
But during instantiation, we don't repeat that check, so only call
check_bitfield_decl later on which can sometimes emit different diagnostics
(so e.g.
bit-field âD<1.0e+0>::dâ width not an integer constant
instead of
width of bit-field âD<N>::dâ has non-integral type âdoubleâ
) but what the second testcase shows, we can ICE during cxx_constant_value
even before that if the type is even more problematic.
The following patch fixes that by repeating the test from grokbitfield
during tsubst_decl.
2026-06-12 Jakub Jelinek <jakub@redhat.com>
PR c++/125674
* pt.cc (tsubst_decl): Diagnose bit-field widths
with invalid type.
* g++.dg/template/bitfield5.C: New test.
* g++.dg/template/bitfield6.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 50ba4a8ca7a51a72514aae55d9fb81732ef7a3bd)
More information about the Gcc-bugs
mailing list