After forward declaration of an enum and when completing it with the
attribute packed, we need to propagate TYPE_PACKED to all main variants.
PR c/116892
gcc/c/ChangeLog:
* c-decl.cc (finish_enum): Propagate TYPE_PACKED.
gcc/testsuite/ChangeLog:
* gcc.dg/pr116892.c: New test.
TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
ENUM_UNDERLYING_TYPE (tem) = ENUM_UNDERLYING_TYPE (enumtype);
+ TYPE_PACKED (tem) = TYPE_PACKED (enumtype);
}
/* Finish debugging output for this type. */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-g -std=gnu23" } */
+
+enum fmt_type;
+
+void foo(const enum fmt_type a);
+
+enum [[gnu::packed]] fmt_type {
+ A
+} const a;
+