GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
c++

c++: Implement C++29 P2953R5 - Adding restrictions to defaulted assignment operator functions [PR125826]

GCC now implements C++29 restrictions on defaulted assignment operators and constructors, aligning with P2953R5.

This commit implements the C++29 feature described in P2953R5, which adds restrictions to defaulted assignment operator functions and, in some cases, defaulted constructors. The changes primarily affect the maybe_delete_defaulted_fn function, altering its behavior for C++29 to issue errors instead of deleting functions in most cases, with specific exceptions. Checks for when a defaulted function should be deleted or ill-formed are consolidated into this function.

In Details

Implements C++29 proposal P2953R5. The maybe_delete_defaulted_fn in method.cc is updated for C++29. It now calls maybe_delete_defaulted_fn for the FUNCTION_RVALUE_QUALIFIED case and generally errors out rather than deleting functions, except for the specific case in [dcl.fct.def.default]/(2.5) that remains deleted if it's the only non-whitelisted difference. Checks for deletion vs. ill-formed status are moved to maybe_delete_defaulted_fn. defaulted_late_check now calls maybe_delete_defaulted_fn unconditionally. Testcases are adjusted for C++29 diagnostics.

For Context
defaulted function
In C++, a special member function (like a constructor or assignment operator) that is declared with the = default specifier, requesting that the compiler generate a standard implementation for it.
assignment operator
A special member function in C++ that overloads the assignment operator (=) for a class, allowing objects of that class to be assigned to each other.
C++29
A potential future standard of the C++ programming language, following C++20 and C++23. Compiler support for future standards often implements proposals before they are officially ratified.
P2953R5
A C++ standardization proposal document (P2953R5) whose title is 'Adding restrictions to defaulted assignment operator functions'. It describes changes to how defaulted assignment operators and constructors are handled.
ill-formed
A C++ code construct that does not conform to the language standard and results in a compile-time diagnostic, but is not necessarily an error that prevents all compilation. It is distinct from 'deleted' or 'static' functions.
Filed Under: c++language-featuredefaulted-functionsc++29