forked from fmtlib/fmt
Update checks for dynamic_cast usage when compiled with no rtti (#3963)
* Rename FMT_USE_TYPEID to FMT_HAS_RTTI and use it as check to enable dynamic_cast usage * FMT_HAS_RTTI->FMT_USE_RTTI
This commit is contained in:
@ -279,6 +279,17 @@ import std;
|
|||||||
# define FMT_UNICODE 1
|
# define FMT_UNICODE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Check if rtti is available.
|
||||||
|
#ifndef FMT_USE_RTTI
|
||||||
|
// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
|
||||||
|
# if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
|
||||||
|
defined(__INTEL_RTTI__) || defined(__RTTI)
|
||||||
|
# define FMT_USE_RTTI 1
|
||||||
|
# else
|
||||||
|
# define FMT_USE_RTTI 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define FMT_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
|
#define FMT_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
|
||||||
|
|
||||||
// Enable minimal optimizations for more compact code in debug mode.
|
// Enable minimal optimizations for more compact code in debug mode.
|
||||||
|
@ -44,12 +44,12 @@ auto get_file(std::filebuf&) -> FILE*;
|
|||||||
inline auto write_ostream_unicode(std::ostream& os, fmt::string_view data)
|
inline auto write_ostream_unicode(std::ostream& os, fmt::string_view data)
|
||||||
-> bool {
|
-> bool {
|
||||||
FILE* f = nullptr;
|
FILE* f = nullptr;
|
||||||
#if FMT_MSC_VERSION
|
#if FMT_MSC_VERSION && FMT_USE_RTTI
|
||||||
if (auto* buf = dynamic_cast<std::filebuf*>(os.rdbuf()))
|
if (auto* buf = dynamic_cast<std::filebuf*>(os.rdbuf()))
|
||||||
f = get_file(*buf);
|
f = get_file(*buf);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
#elif defined(_WIN32) && defined(__GLIBCXX__)
|
#elif defined(_WIN32) && defined(__GLIBCXX__) && FMT_USE_RTTI
|
||||||
auto* rdbuf = os.rdbuf();
|
auto* rdbuf = os.rdbuf();
|
||||||
if (auto* sfbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char>*>(rdbuf))
|
if (auto* sfbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char>*>(rdbuf))
|
||||||
f = sfbuf->file();
|
f = sfbuf->file();
|
||||||
|
@ -62,17 +62,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check if typeid is available.
|
|
||||||
#ifndef FMT_USE_TYPEID
|
|
||||||
// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
|
|
||||||
# if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
|
|
||||||
defined(__INTEL_RTTI__) || defined(__RTTI)
|
|
||||||
# define FMT_USE_TYPEID 1
|
|
||||||
# else
|
|
||||||
# define FMT_USE_TYPEID 0
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// For older Xcode versions, __cpp_lib_xxx flags are inaccurately defined.
|
// For older Xcode versions, __cpp_lib_xxx flags are inaccurately defined.
|
||||||
#ifndef FMT_CPP_LIB_FILESYSTEM
|
#ifndef FMT_CPP_LIB_FILESYSTEM
|
||||||
# ifdef __cpp_lib_filesystem
|
# ifdef __cpp_lib_filesystem
|
||||||
@ -443,7 +432,7 @@ struct formatter<
|
|||||||
if (it == end || *it == '}') return it;
|
if (it == end || *it == '}') return it;
|
||||||
if (*it == 't') {
|
if (*it == 't') {
|
||||||
++it;
|
++it;
|
||||||
with_typename_ = FMT_USE_TYPEID != 0;
|
with_typename_ = FMT_USE_RTTI != 0;
|
||||||
}
|
}
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
@ -455,7 +444,7 @@ struct formatter<
|
|||||||
if (!with_typename_)
|
if (!with_typename_)
|
||||||
return detail::write_bytes<Char>(out, string_view(ex.what()));
|
return detail::write_bytes<Char>(out, string_view(ex.what()));
|
||||||
|
|
||||||
#if FMT_USE_TYPEID
|
#if FMT_USE_RTTI
|
||||||
const std::type_info& ti = typeid(ex);
|
const std::type_info& ti = typeid(ex);
|
||||||
# ifdef FMT_HAS_ABI_CXA_DEMANGLE
|
# ifdef FMT_HAS_ABI_CXA_DEMANGLE
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
Reference in New Issue
Block a user