Skip to content

Case 22 โ€” Method Const Qualifier Changed

Field Value
Verdict ๐Ÿ”ด BREAKING
Category Breaking
Platforms Linux, macOS, Windows
Flags ABI break, API break
Detected ChangeKinds func_cv_changed
Source files browse on GitHub

Verdict: ๐Ÿ”ด BREAKING abicheck verdict: BREAKING

What changes

Version Declaration
v1 class Widget { void get() const; };
v2 class Widget { void get(); };

What breaks at binary level

In the Itanium C++ ABI, const qualification on a member function is part of the mangled symbol name:

  • Widget::get() const โ†’ _ZNK6Widget3getEv (note the K for const)
  • Widget::get() โ†’ _ZN6Widget3getEv

Removing (or adding) const produces a different mangled name. Existing binaries compiled against v1 import _ZNK6Widget3getEv, but v2 only exports _ZN6Widget3getEv. The dynamic linker cannot resolve the symbol โ†’ unresolved symbol error at load time.

Consumer impact

/* consumer compiled against v1 */
const Widget& w = get_widget();
w.get();  /* calls _ZNK6Widget3getEv */

/* v2 library exports _ZN6Widget3getEv (non-const) */
/* โ†’ undefined symbol: _ZNK6Widget3getEv */

Mitigation

  • Keep the old const-qualified method and add a non-const overload if needed.
  • Provide both signatures during a transition period.

Code diff

 class Widget {
 public:
-    void get() const;
+    void get();
 };

Real Failure Demo

Severity: CRITICAL

Scenario: app compiled against old header calls get() const (_ZNK6Widget3getEv). New lib exports only _ZN6Widget3getEv โ€” undefined symbol at runtime.

# Build old lib + app
g++ -shared -fPIC -g old/lib.cpp -Iold -o libwidget.so
g++ -g app.cpp -Iold -L. -lwidget -Wl,-rpath,. -o app
./app
# โ†’ get() const called

# Swap in new lib (const removed)
g++ -shared -fPIC -g new/lib.cpp -Inew -o libwidget.so
./app
# โ†’ ./app: symbol lookup error: undefined symbol: _ZNK6Widget3getEv

Why CRITICAL: const is part of the C++ mangled name (K in _ZNK...). Removing it produces a completely different symbol. Every pre-built binary that calls widget.get() on a const reference fails to load โ€” hard runtime crash.

Why runtime result may differ from verdict

const qualifier on method changes mangled name โ€” symbol lookup error

References


Source files

See also: Examples overview ยท All BREAKING cases ยท Category: Breaking.