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

c++: Fix constexpr exception handling for pointer-to-member types

Corrects constexpr exception handling for pointer-to-member types to align with C++ standard.

This commit addresses several issues in GCC’s handling of exceptions thrown and caught within constexpr contexts, specifically concerning pointer-to-member types. The C++ standard specifies that when catching exceptions by pointer types, the handler receives a pointer to the exception object. However, GCC’s runtime library (libsupc++) did not correctly handle pointer-to-member types in these scenarios, leading to incorrect type information or invalid casts. This change ensures proper runtime handling for pointer-to-member exceptions in constexpr evaluations, aligning with the standard’s requirements for types like __cxa_begin_catch return values and runtime type information resolution.

In Details

Constexpr evaluation of exception handling for pointer-to-member types is complex due to differing semantics between compile-time and runtime exception mechanisms. The standard ([except.handle] 3.3 and 3.4) allows for type mismatches between thrown and caught types, often resolved by runtime conversions. For pointer types, __cxa_begin_catch returns a pointer to the exception object. However, for pointer-to-member types, it returned a pointer *to the pointer-to-member type itself*. This commit corrects this by adjusting how __do_catch in libsupc++ handles these cases, ensuring runtime li…

For Context
constexpr
A keyword in C++ that indicates a variable or function can be evaluated at compile time. This allows for compile-time computation and optimization.
pointer-to-member
A type in C++ that is a pointer to a member (data or function) of a specific class. It is distinct from a regular pointer or a class instance pointer.
exception handling
A mechanism in programming languages to deal with runtime errors or exceptional conditions. In C++, this involves try, catch, and throw keywords.
__cxa_begin_catch
A runtime function from the Itanium C++ ABI that is called when an exception is caught. It is responsible for managing the exception object and its type information.
libsupc++
The standard C++ support library for GCC, providing runtime support for C++ features like exception handling, RTTI, and typeinfo.
typeinfo
A C++ mechanism that provides runtime type information about objects, primarily through the typeid operator.
Filed Under: c++constexprexception handlingruntime