TUESDAY, JULY 7, 2026
c++
C++: Handle nullptr_t in exception conversion checks
Fixes C++ exception handling to correctly match nullptr_t exceptions with pointer handlers.
This commit corrects C++ exception handling by enabling can_convert_eh to properly match std::nullptr_t exceptions with handlers declared to catch pointer or pointer-to-member types. This ensures that nullptr thrown as an exception can be caught by appropriate handlers, preventing potential runtime errors.
In Details
can_convert_eh determines if an exception of type E can be caught by a handler of type H. This patch adds a check for nullptr_t exceptions where H is a pointer type (e.g., int*, char**, or member pointers). Standard C++ rules ([except.handle]) permit catching a nullptr_t with a pointer handler, which was previously missed by GCC's implementation.
For Context
- std::nullptr_t
- The C++ type for the null pointer literal
nullptr. It represents a null pointer value that can be distinguishied from an integer zero. - Exception handling
- A programming construct that allows programs to deal with runtime errors or exceptional conditions by transferring control to a designated handler.
- can_convert_eh
- An internal GCC function that checks if an exception type is convertible to a type that an exception handler can catch, based on C++ standard rules.
- Pointer type
- A data type that stores the memory address of another variable. This includes raw pointers, smart pointers, and pointers to member objects.