https://gcc.gnu.org/g:71f484d02b2b3e8616cd7af27a0d4c72e4c7e977

commit r15-1620-g71f484d02b2b3e8616cd7af27a0d4c72e4c7e977
Author: Marek Polacek <pola...@redhat.com>
Date:   Tue Jun 18 10:50:49 2024 -0400

    c++: ICE with __dynamic_cast redecl [PR115501]
    
    Since r13-3299, build_dynamic_cast_1 calls pushdecl which calls
    duplicate_decls and that in this testcase emits the "conflicting
    declaration" error and returns error_mark_node, so the subsequent
    build_cxx_call crashes on the error_mark_node.
    
            PR c++/115501
    
    gcc/cp/ChangeLog:
    
            * rtti.cc (build_dynamic_cast_1): Return if dcast_fn is erroneous.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/rtti/dyncast8.C: New test.

Diff:
---
 gcc/cp/rtti.cc                       |  2 ++
 gcc/testsuite/g++.dg/rtti/dyncast8.C | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc
index ed69606f4dd..cc006ea927f 100644
--- a/gcc/cp/rtti.cc
+++ b/gcc/cp/rtti.cc
@@ -794,6 +794,8 @@ build_dynamic_cast_1 (location_t loc, tree type, tree expr,
              pop_abi_namespace (flags);
              dynamic_cast_node = dcast_fn;
            }
+         if (dcast_fn == error_mark_node)
+           return error_mark_node;
          result = build_cxx_call (dcast_fn, 4, elems, complain);
          SET_EXPR_LOCATION (result, loc);
 
diff --git a/gcc/testsuite/g++.dg/rtti/dyncast8.C 
b/gcc/testsuite/g++.dg/rtti/dyncast8.C
new file mode 100644
index 00000000000..de23433dd9b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/dyncast8.C
@@ -0,0 +1,15 @@
+// PR c++/115501
+// { dg-do compile }
+
+struct s{virtual void f();};
+struct s1 : s{};
+namespace __cxxabiv1
+{
+  extern "C" void __dynamic_cast(); // { dg-message "previous declaration" }
+}
+void diagnostic_information_impl(s const *se)
+{
+  dynamic_cast<s1 const *>(se);
+}
+
+// { dg-error "conflicting declaration" "" { target *-*-* } 0 }

Reply via email to