]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with __dynamic_cast redecl [PR115501]
authorMarek Polacek <polacek@redhat.com>
Tue, 18 Jun 2024 14:50:49 +0000 (10:50 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 25 Jun 2024 19:07:46 +0000 (15:07 -0400)
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
gcc/testsuite/g++.dg/rtti/dyncast8.C [new file with mode: 0644]

index ed69606f4ddcad6e980f3bcaa1f7245c021608c6..cc006ea927f289feba4122f98c4f86677919381c 100644 (file)
@@ -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 (file)
index 0000000..de23433
--- /dev/null
@@ -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 }