GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Breaking Change

Enable dangling checks in std::pair and std::tuple.

Dangling reference checks are now enabled by default for std::pair and std::tuple.

Checks for dangling references in std::pair and std::tuple constructors are now enabled by default, not just in debug mode. This change makes it ill-formed to create pairs or tuples with dangling references, preventing potential undefined behavior. Programs that previously relied on such constructs in unexecuted code paths may need to be updated.

In Details

This commit removes the conditional compilation guards (_GLIBCXX_DEBUG) around dangling reference checks in std::pair and std::tuple. Previously, these checks were experimental or only enabled in debug builds. Now, they are enabled by default for all builds, enforcing stricter type safety for these common container types. This aligns with the move towards enabling these checks unconditionally in C++20 and addresses a gap in earlier standards.

For Context
std::pair
A C++ standard library template that combines two objects of potentially different types into a single object. It's commonly used to return multiple values from a function or to associate keys with values.
std::tuple
A C++ standard library template that represents a fixed-size collection of heterogeneous values. It's a more general version of std::pair, allowing for any number of elements.
dangling reference
A reference that points to an object that has been deallocated or is no longer valid. Accessing a dangling reference leads to undefined behavior.
undefined behavior (UB)
Behavior that results from an erroneous program construct or invalid input, for which the C++ standard imposes no requirements. Anything can happen, including incorrect results, crashes, or security vulnerabilities.
Filed Under: libstdc++safetyC++20