https://gcc.gnu.org/g:cc2a9b13bbf9994f5f27c08a95314b07f4dd7730

commit r17-2201-gcc2a9b13bbf9994f5f27c08a95314b07f4dd7730
Author: Egas Ribeiro <[email protected]>
Date:   Tue Jul 7 12:52:08 2026 -0400

    c++: handle nullptr_t in can_convert_eh
    
    can_convert_eh implements the [except.handle] matching rules, but did
    not cover the case of a std::nullptr_t exception being caught by a
    handler of pointer or pointer-to-member type.  Add it.
    
    gcc/cp/ChangeLog:
            * except.cc (can_convert_eh): Handle a nullptr_t exception
            caught by a pointer or pointer-to-member handler.
    
    gcc/testsuite/ChangeLog:
            * g++.dg/eh/can-convert-nullptr.C: New test.
    
    Signed-off-by: Egas Ribeiro <[email protected]>

Diff:
---
 gcc/cp/except.cc                              | 3 +++
 gcc/testsuite/g++.dg/eh/can-convert-nullptr.C | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc
index e1e082ef1acc..c4b5c388f9b8 100644
--- a/gcc/cp/except.cc
+++ b/gcc/cp/except.cc
@@ -982,6 +982,9 @@ can_convert_eh (tree to, tree from)
   if (same_type_ignoring_top_level_qualifiers_p (to, from))
     return true;
 
+  if (NULLPTR_TYPE_P (from) && TYPE_PTR_OR_PTRMEM_P (to))
+    return true;
+
   if (TYPE_PTR_P (to) && TYPE_PTR_P (from))
     {
       to = TREE_TYPE (to);
diff --git a/gcc/testsuite/g++.dg/eh/can-convert-nullptr.C 
b/gcc/testsuite/g++.dg/eh/can-convert-nullptr.C
new file mode 100644
index 000000000000..b609234591e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/can-convert-nullptr.C
@@ -0,0 +1,7 @@
+// { dg-do compile { target c++11 } }
+
+int main() {
+  try { throw nullptr; }
+  catch (void *) {}
+  catch (decltype(nullptr)) {} // { dg-warning "will be caught by earlier 
handler" }
+}

Reply via email to