Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt/std.h requires rtti #3464

Closed
danakj opened this issue May 27, 2023 · 8 comments
Closed

fmt/std.h requires rtti #3464

danakj opened this issue May 27, 2023 · 8 comments

Comments

@danakj
Copy link
Contributor

danakj commented May 27, 2023

Version: 10.0.0

I would like to use fmt/std.h to format std::string_view and such. I am compiling without RTTI.

But the std::exception specialization uses:

    const std::type_info& ti = typeid(ex);

which does not compile with RTTI disabled in Clang or GCC.

/home/runner/work/subspace/subspace/third_party/fmt/include/fmt/std.h:290:32: error: use of typeid requires -frtti
    const std::type_info& ti = typeid(ex);
                               ^

Could we split this type which requires RTTI into a separate header?

@Dani-Hub
Copy link
Contributor

The alternative solution would be to conditionally deactivate those parts of fmt/std.h requiring RTTI when RTTI is deactivated. From a user-point of view this seems to me the better approach.

@danakj
Copy link
Contributor Author

danakj commented May 27, 2023

I would be okay with either! Would that also be more compatible with being in a module?

@vitaut
Copy link
Contributor

vitaut commented May 27, 2023

Same as #3426. A PR to make RTTI usage condition (but not splitting std.h) would be welcome.

@danakj
Copy link
Contributor Author

danakj commented May 27, 2023

Ok thanks.

Here’s a method to determine RTTI state, did not test it to verify yet: https://gist.github.com/brimston3/2be168bb423c83b0f469c0be56e66d31

@Dani-Hub
Copy link
Contributor

Ok thanks.

Here’s a method to determine RTTI state, did not test it to verify yet: https://gist.github.com/brimston3/2be168bb423c83b0f469c0be56e66d31

According to boost/config/compiler/gcc.hpp#L122 for GCC you need to test for the GCC version as well to be sure about RTTI being enabled, but it is possible that fmtlib doesn't support older GCCs anyway (You should check).

Following further the boost RTTI detection for other compilers there are some further checks helpful (e.g. for intel there exists INTEL_RTTI) and others. I recommend to search for RTTI in the include/boost/config/ directory to collect them.

@danakj
Copy link
Contributor Author

danakj commented May 31, 2023

Works for MSVC, GCC, and Clang: https://godbolt.org/z/W5v595jo8

I can't test Intel on compiler explorer.

@danakj
Copy link
Contributor Author

danakj commented May 31, 2023

Compiler support:

So yeah, I'll grab all of those from boost. Thanks @Dani-Hub

@danakj
Copy link
Contributor Author

danakj commented May 31, 2023

but it is possible that fmtlib doesn't support older GCCs anyway

From https://github.com/fmtlib/fmt/blob/bd393456ed94a5d64bb6078aa3fa477ceeb621d9/doc/index.rst#portability

These are available in GCC 4.8, Clang 3.4, MSVC 19.0 (2015) and more recent compiler version. For older compilers use {fmt} version 4.x which is maintained and only requires C++98.

That check is for gcc 4.3, but fmt 10+ requires GCC 4.8, so I will omit that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants