From 28757cdd55e25aebed00162048095ca31bd62577 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Sun, 16 Apr 2023 09:25:27 +0200 Subject: [PATCH] fix and improve module: * export public documented API * don't export `namespace detail` * add `std.h` into module * add missing namespace qualification in `xchar.h` * fix call to `detail::get_iterator` in `xchar.h` * fix ambiguous overload of `detail::isfinite` in `chrono.h` --- include/fmt/args.h | 2 ++ include/fmt/chrono.h | 2 +- include/fmt/core.h | 14 ++++++++++++++ include/fmt/std.h | 16 ++++++++++++---- include/fmt/xchar.h | 4 ++-- src/fmt.cc | 7 +++++++ 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index a3966d1407198..a977bf14021ee 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -59,6 +59,7 @@ class dynamic_arg_list { } }; } // namespace detail +FMT_BEGIN_EXPORT /** \rst @@ -229,6 +230,7 @@ class dynamic_format_arg_store } }; +FMT_END_EXPORT FMT_END_NAMESPACE #endif // FMT_ARGS_H_ diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 714c1014ead67..cdf728490afc1 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1666,7 +1666,7 @@ struct chrono_format_checker : null_chrono_spec_handler { FMT_CONSTEXPR void on_duration_unit() {} }; -template ::value)> +template ::value && has_isfinite::value)> inline bool isfinite(T) { return true; } diff --git a/include/fmt/core.h b/include/fmt/core.h index 08c8cd1683f97..079f176e7cd54 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -258,6 +258,7 @@ FMT_GCC_PRAGMA("GCC optimize(\"Og\")") #endif FMT_BEGIN_NAMESPACE +FMT_BEGIN_EXPORT // Implementations of enable_if_t and other metafunctions for older systems. template @@ -295,6 +296,7 @@ inline auto format_as(std::byte b) -> unsigned char { } #endif +FMT_END_EXPORT namespace detail { // Suppresses "unused variable" warnings with the method described in // https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/. @@ -386,6 +388,7 @@ FMT_CONSTEXPR inline auto is_utf8() -> bool { uchar(section[1]) == 0xA7); } } // namespace detail +FMT_BEGIN_EXPORT /** An implementation of ``std::basic_string_view`` for pre-C++17. It provides a @@ -502,6 +505,7 @@ using string_view = basic_string_view; template struct is_char : std::false_type {}; template <> struct is_char : std::true_type {}; +FMT_END_EXPORT namespace detail { // A base class for compile-time strings. @@ -635,6 +639,7 @@ struct error_handler { } }; } // namespace detail +FMT_BEGIN_EXPORT /** String's character type. */ template using char_t = typename detail::char_t_impl::type; @@ -713,6 +718,7 @@ template class basic_format_parse_context { using format_parse_context = basic_format_parse_context; +FMT_END_EXPORT namespace detail { // A parse context with extra data used only in compile-time checks. template @@ -752,6 +758,7 @@ class compile_parse_context : public basic_format_parse_context { } }; } // namespace detail +FMT_BEGIN_EXPORT template FMT_CONSTEXPR void basic_format_parse_context::do_check_arg_id(int id) { @@ -799,6 +806,7 @@ struct is_contiguous> : std::true_type {}; class appender; +FMT_END_EXPORT namespace detail { template @@ -1476,6 +1484,7 @@ enum { max_packed_args = 62 / packed_arg_bits }; enum : unsigned long long { is_unpacked_bit = 1ULL << 63 }; enum : unsigned long long { has_named_args_bit = 1ULL << 62 }; } // namespace detail +FMT_BEGIN_EXPORT // An output iterator that appends to a buffer. // It is used to reduce symbol sizes for the common case. @@ -1594,6 +1603,7 @@ FMT_CONSTEXPR FMT_INLINE auto visit_format_arg( return vis(monostate()); } +FMT_END_EXPORT namespace detail { template @@ -1710,6 +1720,7 @@ FMT_CONSTEXPR inline auto make_arg(T&& value) -> basic_format_arg { return make_arg(value); } } // namespace detail +FMT_BEGIN_EXPORT // Formatting context. template class basic_format_context { @@ -1998,6 +2009,7 @@ enum type FMT_ENUM_UNDERLYING_TYPE(unsigned char){none, minus, plus, space}; } using sign_t = sign::type; +FMT_END_EXPORT namespace detail { // Workaround an array initialization issue in gcc 4.8. @@ -2024,6 +2036,7 @@ template struct fill_t { } }; } // namespace detail +FMT_BEGIN_EXPORT enum class presentation_type : unsigned char { none, @@ -2068,6 +2081,7 @@ template struct format_specs { localized(false) {} }; +FMT_END_EXPORT namespace detail { enum class arg_id_kind { none, index, name }; diff --git a/include/fmt/std.h b/include/fmt/std.h index 1583ca213296d..b29978ba3bad1 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -73,6 +73,7 @@ inline void write_escaped_path( } } // namespace detail +FMT_BEGIN_EXPORT template struct formatter @@ -91,16 +92,20 @@ struct formatter basic_string_view(quoted.data(), quoted.size()), ctx); } }; +FMT_END_EXPORT FMT_END_NAMESPACE #endif FMT_BEGIN_NAMESPACE +FMT_BEGIN_EXPORT template struct formatter : basic_ostream_formatter {}; +FMT_END_EXPORT FMT_END_NAMESPACE #ifdef __cpp_lib_optional FMT_BEGIN_NAMESPACE +FMT_BEGIN_EXPORT template struct formatter, Char, std::enable_if_t::value>> { @@ -139,11 +144,13 @@ struct formatter, Char, return detail::write(out, ')'); } }; +FMT_END_EXPORT FMT_END_NAMESPACE #endif // __cpp_lib_optional #ifdef __cpp_lib_variant FMT_BEGIN_NAMESPACE +FMT_BEGIN_EXPORT template struct formatter { template FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { @@ -159,7 +166,7 @@ template struct formatter { } }; -namespace detail { +FMT_BEGIN_DETAIL_NAMESPACE template using variant_index_sequence = @@ -191,8 +198,7 @@ auto write_variant_alternative(OutputIt out, const T& v) -> OutputIt { return write(out, v); } -} // namespace detail - +FMT_END_DETAIL_NAMESPACE template struct is_variant_like { static constexpr const bool value = detail::is_variant_like_::value; }; @@ -231,11 +237,12 @@ struct formatter< return out; } }; +FMT_END_EXPORT FMT_END_NAMESPACE #endif // __cpp_lib_variant FMT_BEGIN_NAMESPACE - +FMT_BEGIN_EXPORT template struct formatter { template FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { @@ -338,6 +345,7 @@ struct formatter< return out; } }; +FMT_END_EXPORT FMT_END_NAMESPACE #endif // FMT_STD_H_ diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index d7b2fa47f99da..4b87f8d12811f 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -170,7 +170,7 @@ inline auto vformat_to( auto&& buf = detail::get_buffer(out); vformat_to(buf, detail::to_string_view(format_str), args, detail::locale_ref(loc)); - return detail::get_iterator(buf); + return detail::get_iterator(buf, out); } template < @@ -181,7 +181,7 @@ template < inline auto format_to(OutputIt out, const Locale& loc, const S& format_str, Args&&... args) -> typename std::enable_if::type { - return vformat_to(out, loc, to_string_view(format_str), + return vformat_to(out, loc, detail::to_string_view(format_str), fmt::make_format_args>(args...)); } diff --git a/src/fmt.cc b/src/fmt.cc index bda3ce525bb7f..d588764a4868c 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -14,19 +14,25 @@ module; #include #include #include +#include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include #include #include +#include #include +#include #if _MSC_VER # include @@ -75,6 +81,7 @@ export module fmt; #include "fmt/os.h" #include "fmt/printf.h" #include "fmt/xchar.h" +#include "fmt/std.h" // gcc doesn't yet implement private module fragments #if !FMT_GCC_VERSION