Case 19: Enum Member Removed¶
| Field | Value |
|---|---|
| Verdict | 🔴 BREAKING |
| Category | Breaking |
| Classification | Rule |
| Platforms | Linux, macOS, Windows |
| Flags | ABI break, API break |
Detected ChangeKinds |
enum_member_removed |
| Source files | catalog/cases/case19_enum_member_removed/ |
| Rule family | enum-member-removed |
| Subject | Enum ABI and API changes |
Category: Breaking | Verdict: 🔴 BREAKING
Verdict and consumer impact¶
Three distinct things change here, and they should not be conflated:
- Source break.
FOOis gone from the header, so consumer source that names it no longer compiles. - Value-contract break for already-built consumers. Code compiled
against old still holds the constant
2and may store, transmit, orswitchon it; the new library no longer defines that value as aStatus, so persisted data, protocol messages and switch arms built around it are silently mishandled. This is why abicheck classifiesenum_member_removedasBREAKING. - Not a layout break. The enum's representation does not change: on
the tested targets (x86-64 SysV, GCC and Clang)
Statuskeeps the same underlying type and size with or withoutFOO, so no struct offset, parameter slot or return register moves. An enumerator removal is not a universal size/calling-convention change — check the enum's representation (enum_underlying_size_changed) separately per ABI.
The fixture additionally changes behavior: get_status() returns ERROR
(1) where it used to return FOO (2). The runtime witness below
therefore demonstrates the changed result contract the old consumer relies
on, not a layout mismatch; a removal that kept the library's numeric results
unchanged would still be (1) and (2), but would not fail that particular
smoke.
Old/new diff¶
| old/lib.h | new/lib.h |
|---|---|
enum Status { OK = 0, ERROR = 1, FOO = 2 }; |
enum Status { OK = 0, ERROR = 1 }; |
old/lib.c: get_status() returns FOO |
new/lib.c: get_status() returns ERROR |
abicheck command¶
gcc -shared -fPIC -g old/lib.c -Iold -o libfoo_v1.so
gcc -shared -fPIC -g new/lib.c -Inew -o libfoo_v2.so
abicheck compare libfoo_v1.so libfoo_v2.so
Expected abicheck finding¶
Verdict: BREAKING (exit 4)
- enum_member_removed: Enum member removed: Status::FOO (2)
> Old code uses a constant that no longer exists; compile error for
source, stale value for binaries.
Minimum evidence¶
min_evidence: L1 — DWARF's enumeration-type debug info
(DW_TAG_enumeration_type / DW_TAG_enumerator) records each named member
and its value for both versions, so -g alone (no public headers) is enough
to detect the removed member.
Why abicheck catches it¶
DWARF records every enumerator name and constant value under the enum's
DW_TAG_enumeration_type entry; abicheck diffs the two versions' member
sets directly from debug info and flags a name present only in old as
enum_member_removed.
Runtime failure demonstration¶
Severity: CRITICAL (changed result contract)
Scenario: compile app against old (it checks for FOO), swap in new
.so without recompile.
gcc -shared -fPIC -g old/lib.c -Iold -o libstatus.so
gcc -g app.c -Iold -L. -lstatus -Wl,-rpath,. -o app
./app # FOO exit 0
gcc -shared -fPIC -g new/lib.c -Inew -o libstatus.so # swap, no recompile
./app # WRONG RESULT: expected FOO(2), got 1 exit 1
The app's compiled-in check if (s == FOO) still compares against the
constant 2, but new's get_status() now returns ERROR (1) for the
situation it used to report as FOO. That is the behavior change the
fixture makes alongside the removal; the enum's own size and the call's
register usage are unchanged.
Safe redesign¶
Never remove a released enum member; deprecate it instead and keep its
numeric value reserved. Map legacy values deliberately in
deserialization/protocol handling, and use an explicit sentinel
(STATUS_MAX) to define the valid range rather than relying on "whatever
values currently exist."
Real-world example: protocol and status-code enums that get "cleaned up" between releases are a recurring source of this — any peer or persisted record built against the old value set silently misinterprets removed codes.
References¶
Source files¶
new/old/CMakeLists.txtapp.c
See also: Compatibility Catalog · All BREAKING cases · Category: Breaking · Rule: Enumerator removed · Subject: Enum ABI and API changes.