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

C++: Implement C++26 P3769R1 deallocation clarification for placement new

Implements C++26 P3769R1, clarifying deallocation for placement new by selecting the correct deallocation function.

This commit implements the C++26 paper P3769R1, which clarifies the deallocation process for objects allocated with placement new. The compiler now correctly selects the appropriate deallocation function from a list of candidates, considering template argument deduction and constraints. This change resolves ambiguities in handling deallocation during exceptions and aligns GCC’s behavior with the standard’s intent, particularly for cases previously influenced by the pending CWG901 resolution. A new test case placement-new1.C is included.

In Details

This commit implements C++26 P3769R1, a DR for CWG2518, to correctly handle deallocation of objects allocated with placement new, especially in exception scenarios. GCC's prior implementation of CWG901 had a different resolution. The changes in call.cc modify build_op_delete_call_1 to iterate over the found deallocation functions, perform template argument deduction, filter candidates by parameter types and constraints, and select a single function if available. If no single function is found, the object is not destructed on throw. The placement_args argument is introduced to facilitate…

For Context
placement new
A C++ operator that allocates memory but does not initialize the object. It's typically used to construct an object in pre-allocated memory, often with custom constructors that take additional arguments.
deallocation function
The function responsible for freeing memory (e.g., operator delete). For placement new, there's a specific set of rules for selecting the correct deallocation function, especially when exceptions occur.
P3769R1
A C++ standardization proposal that clarifies the rules for deallocation functions used with placement new, particularly in the context of exceptions and template argument deduction.
DR
Defect Report. A mechanism in C++ standardization to correct ambiguities or errors in the language standard, often applied retroactively.
CWG901
A Core Working Group (CWG) issue in the C++ standardization process that addresses the interaction between placement new, deallocation, and exceptions.
template argument deduction
The process by which the compiler automatically determines the types of template arguments based on the function arguments provided when a function template is called.
Filed Under: c++exception handlingplacement newstandardization