On 6/18/24 10:58, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

-- >8 --
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.
---
  gcc/cp/rtti.cc                       |  2 ++
  gcc/testsuite/g++.dg/rtti/dyncast8.C | 15 +++++++++++++++
  2 files changed, 17 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/rtti/dyncast8.C

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 }

base-commit: e4f938936867d8799775d1455e67bd3fb8711afd

Reply via email to