Unlike C, C++ doesn't mark enums shortened by -fshort-enums as packed. This makes for undesirable warning differences between C and C++, e.g. c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early*.c triggers a warning about a type cast from a pointer to enum that, when packed, might not be sufficiently aligned.
This change is not enough for that warning to trigger. The tree expression generated by the C++ front-end is also a little too complicated for us get to the base pointer. A separate patch takes care of that. Regstrapped on x86_64-linux-gnu, also tested on arm-eabi with default cpu on trunk, and with tms570 on gcc-13. Ok to install? for gcc/cp/ChangeLog * decl.cc (finish_enum_value_list): Set TYPE_PACKED if use_short_enum, and propagate it to variants. --- gcc/cp/decl.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 038c5ab71f201..f6d5645d5080f 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -16881,6 +16881,12 @@ finish_enum_value_list (tree enumtype) /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */ if (flag_strict_enums) set_min_and_max_values_for_integral_type (enumtype, precision, sgn); + + if (use_short_enum) + { + TYPE_PACKED (enumtype) = use_short_enum; + fixup_attribute_variants (enumtype); + } } else underlying_type = ENUM_UNDERLYING_TYPE (enumtype); -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer More tolerance and less prejudice are key for inclusion and diversity Excluding neuro-others for not behaving ""normal"" is *not* inclusive