Originally reported on Community Hub release announcement:
When trying to update from 4.1.4 to 4.3.0, compilations failed due to lack of RTTI:
../../../../../../../../../../objectbox/src/main/cpp/external/mongo-cxx-driver/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/mongoc_error.hh:111:26: error: use of dynamic_cast requires -frtti 111 | if (auto const ptr = dynamic_cast<v1::server_error const*>(&ex)) { | ^ 1 error generated.Is using dynamic_cast an oversight there, or is RTTI now required?
Is using dynamic_cast an oversight there, or is RTTI now required?P.S.: To clarify, we disable RTTI in some configurations and it has worked without in mongocxx for many versions.
This is the commit: https://github.com/mongodb/mongo-cxx-driver/commit/82f77b60b9d134c1104272727c0e2bee51beb0ca
And looking at the code in question, it seems to be some kind of exception mapping:
template <typename exception_type> [[noreturn]] void throw_exception(v1::exception const& ex) { if (auto const ptr = dynamic_cast<v1::server_error const*>(&ex)) { throw exception_type{ ptr->code(), bsoncxx::v_noabi::document::value{bsoncxx::v_noabi::from_v1(ptr->raw())}, ptr->what()}; } throw exception_type{ex.code(), ex.what()}; }Maybe the dynamic cast could be avoided by overloading with a v1::server_error parameter - if callers still have the full type info.
Also, just for my personal curiosity, why does this exception mapping happen in the first place?