If a program has no other dependencies on libstdc++, we shouldn't require it
just for __cxa_pure_virtual, which is only there to give a prettier
diagnostic before crashing the program; resolving the reference to NULL will
also crash, just without the diagnostic.
gcc/cp/ChangeLog
2020-05-11 Jason Merrill <jason@redhat.com>
* decl.c (cxx_init_decl_processing): Call declare_weak for
__cxa_pure_virtual.
+2020-05-11 Jason Merrill <jason@redhat.com>
+
+ * decl.c (cxx_init_decl_processing): Call declare_weak for
+ __cxa_pure_virtual.
+
2020-05-11 Jason Merrill <jason@redhat.com>
* pt.c (instantiate_class_template_1): Call tsubst_expr for
abort_fndecl
= build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
+ if (flag_weak)
+ /* If no definition is available, resolve references to NULL. */
+ declare_weak (abort_fndecl);
/* Perform other language dependent initializations. */
init_class_processing ();
--- /dev/null
+// Test that we don't need libsupc++ just for __cxa_pure_virtual.
+// { dg-do link }
+// { dg-require-weak }
+// { dg-additional-options "-fno-rtti -nodefaultlibs -lc" }
+
+struct A
+{
+ int i;
+ virtual void f() = 0;
+ A(): i(0) {}
+};
+
+struct B: A
+{
+ virtual void f() {}
+};
+
+int main()
+{
+ B b;
+}