C++ deallocating functions default to noexcept for C++11
Ensures C++ deallocation functions (like operator delete) are correctly marked as noexcept by default.
This change enforces the C++11 standard’s rule that deallocation functions without explicit exception specifiers are implicitly non-throwing. Previously, GCC only applied this implicitly to destructors. Now, operator delete and operator delete[], both global and class-member versions, will also be defaulted to noexcept. This change may affect name mangling for code that relies on precise exception specifications of these functions.
In Details
This commit modifies decl.cc's grokfndecl to set the noexcept_true_spec for C++11 deallocation functions (operator delete, operator delete[]) when their raises tree is NULL_TREE. This aligns GCC’s behavior with the C++ standard (e.g., [except.spec#9]), which mandates a non-throwing exception specification for such functions by default. This change is reflected in name mangling, distinguishing between explicitly and implicitly noexcept functions, which could impact reflection or other metaprogramming techniques.
- noexcept
- A C++ keyword used to declare that a function will not throw exceptions. Functions marked
noexceptcan be optimized more aggressively by the compiler and affect function mangling. - deallocation function
- In C++, a function responsible for freeing memory that was previously allocated. This typically includes
operator deleteandoperator delete[], which are called afternewandnew[]expressions, respectively. - exception specification
- A declaration in C++ that specifies whether a function might throw certain exceptions. The
noexceptspecifier is a modern form of exception specification. - name mangling
- The process by which C++ compilers alter function and variable names to encode additional information such as function arguments, namespace, and class scope. This allows the linker to resolve calls to overloaded functions and member functions correctly.
- C++11
- A major revision of the C++ programming language standard, introducing many new features and improvements over C++03.