Skip to content

Case 232: Factory Ownership Convention Changed

Field Value
Verdict ✅ NO_CHANGE
Category No Change
Classification Rule
Platforms Linux
Flags Bad practice
Detected ChangeKinds —
Source files catalog/cases/case232_factory_ownership_convention_changed/
Rule family factory-ownership-convention-changed
Subject Behavioral breaks outside static evidence

Category: No Change (declared interface) | Verdict: ✅ NO_CHANGE — with a separate behavioral break

Verdict and consumer impact

ui::make_widget(int) keeps its declaration, symbol, the Widget layout and the library's imports. Only the ownership of the returned raw pointer changes: v1 returns a new object per call that the caller owns and deletes; v2 caches one widget per id and keeps ownership. Old consumers now share state they believe is private, and their delete frees memory the library still uses (double free, use after free).

This is a behavioral break, not a source (API) or binary (ABI) break. As a statement about the declared interface the verdict is NO_CHANGE, and that stays true even with build data and sources (see below). The break is recorded in ground_truth.json as behavioral_break: true with truth_scope: declared-interface.

Old/new diff

v1.cpp v2.cpp
return new Widget{id, 1}; static Widget *cache[64]; ... return slot; (library-owned)

v1.h and v2.h are identical.

abicheck command

g++ -shared -fPIC -g v1.cpp -o libv1.so
g++ -shared -fPIC -g v2.cpp -o libv2.so
abicheck compare libv1.so libv2.so --header old=v1.h --header new=v2.h

Expected abicheck finding

Compatibility: NO_CHANGE | Policy: strict_abi | Gate: ACCEPTED (exit 0)
Findings: 0 detected; 0 retained (0 gating, 0 non-gating); 0 review groups.

No ChangeKind is expected. The absence is the detection control; the behavioral regression is recorded separately.

Minimum evidence

min_evidence: L2. The public header AST is what establishes that the published declaration is unchanged. Nothing deeper adds a fact: the case was also compared at --depth source with compile_commands.json and both source trees, and the result is still NO_CHANGE.

Why abicheck reports nothing

abicheck's deterministic checks compare what the artifacts declare: exported symbols, DWARF types and layout, header declarations, build flags, and source-graph dependencies. All of those are identical here. The change sits in an out-of-line function body, and its meaning (who owns the object behind a raw Widget*) exists only in documentation. No static rule can tell a bug fix from a contract break in a function body, so abicheck correctly does not guess. That is why ground_truth.json records truth_scope: declared-interface and a separate behavioral_break: true: NO_CHANGE here does not mean "safe to ship". See Behavioral & Semantic Compatibility.

Runtime failure demonstration

Severity: an unchanged old consumer breaks at runtime; no static tool shows it.

g++ -shared -fPIC -g v1.cpp -o libv1.so
g++ -g app.cpp -L. -lv1 -Wl,-rpath,'$ORIGIN' -o app
./app            # a=0x...2b0 b=0x...2d0 b->value=1               exit 0
g++ -shared -fPIC -g v2.cpp -o libv1.so   # swap in v2, no recompile
./app            # a=0x...2d4 b=0x...2d4 b->value=5
                 # WRONG RESULT: widgets are shared, not caller-owned  exit 1

Safe redesign

Put ownership in the type. Return std::unique_ptr<Widget> for a caller-owned object, or std::shared_ptr<Widget> / a reference for a library-owned one. Switching between them changes the return type, which abicheck reports. Replacing the exported factory's return type in place is itself an ABI break, so add a differently named typed factory or make the change in an ABI-major release. With a raw pointer, add a new function (get_widget(id)) for the cached object and keep make_widget allocating.

Cross-tool comparison

abidiff and ABICC also report no change: they compare the same symbols, types and declarations. Catching this break needs a test that runs a consumer against the new library (the app.cpp above is such a test).


Ground-truth provenance

Behavioral break: Not a compatibility claim for the release. A static comparison at every evidence depth (binary, headers, build data, sources) sees the same declaration, the same symbol and the same layout, so NO_CHANGE is the truth only for the declared interface. The runtime witness breaks a valid old consumer: app.cpp creates two widgets for one id and edits one; against v1 they are independent (exit 0), against v2 both pointers are the same shared object (exit 1), and the consumer's delete would free library-owned memory. A raw Widget* carries no ownership, so no deterministic detector can see the change.

Source files

  • CMakeLists.txt
  • app.cpp
  • v1.cpp
  • v1.h
  • v2.cpp
  • v2.h

See also: Compatibility Catalog · All NO_CHANGE cases · Category: No Change · Rule: Factory ownership convention changed · Subject: Behavioral breaks outside static evidence.