From 0f6e7165489c392e717a16adc449001f17fa2d87 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 9 Jun 2024 04:50:29 +0800 Subject: [PATCH] Fix missing includes in fmt.cc (#3994) This causes duplicated std definitions in the fmt module --- CMakeLists.txt | 2 ++ include/fmt/base.h | 9 ++++++--- include/fmt/chrono.h | 3 +-- src/fmt.cc | 5 +++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0898e5bddd04..f14a49c41f16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,8 @@ function(add_module_library name) target_compile_options(${name} PUBLIC -fmodules-ts) endif () + target_compile_definitions(${name} PRIVATE FMT_MODULE) + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND CMAKE_GENERATOR STREQUAL "Ninja") target_sources(${name} PUBLIC FILE_SET fmt TYPE CXX_MODULES FILES ${sources}) else() diff --git a/include/fmt/base.h b/include/fmt/base.h index 6b1d8140c29b..2e10a4c3b423 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -8,9 +8,12 @@ #ifndef FMT_BASE_H_ #define FMT_BASE_H_ -#include // CHAR_BIT -#include // FILE -#include // strlen +// c headers are preferable for performance reasons +#ifndef FMT_MODULE +# include // CHAR_BIT +# include // FILE +# include // strlen +#endif #ifndef FMT_IMPORT_STD // is also included transitively from . diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index f47f17586e64..77d0403246ac 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2144,8 +2144,7 @@ struct formatter : private formatter { if (use_tm_formatter_) return formatter::format(time, ctx); detail::get_locale loc(false, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_day_of_month(detail::numeric_system::standard, - detail::pad_type::zero); + w.on_day_of_month(detail::numeric_system::standard, detail::pad_type::zero); return w.out(); } }; diff --git a/src/fmt.cc b/src/fmt.cc index bb3845f2f964..b7e5ccd4c813 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -6,6 +6,7 @@ module; # include # include # include +# include # include # include # include @@ -13,6 +14,7 @@ module; # include # include # include +# include # include # include # include @@ -22,6 +24,7 @@ module; # include # include # include +# include # include # include # include @@ -104,7 +107,9 @@ extern "C++" { #if FMT_OS # include "fmt/os.h" #endif +#include "fmt/ostream.h" #include "fmt/printf.h" +#include "fmt/ranges.h" #include "fmt/std.h" #include "fmt/xchar.h"