From d0a29c9de0fec04fde19da9ed7bf321634e29728 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 9 Jun 2024 15:29:15 +0000 Subject: [PATCH] Guard more system headers by `FMT_MODULE` --- include/fmt/args.h | 2 +- include/fmt/base.h | 4 ++-- include/fmt/chrono.h | 2 +- include/fmt/compile.h | 2 +- include/fmt/format-inl.h | 13 ++++++++----- include/fmt/format.h | 6 +++--- include/fmt/os.h | 14 ++++++++------ include/fmt/ostream.h | 2 +- include/fmt/printf.h | 2 +- include/fmt/ranges.h | 2 +- include/fmt/std.h | 4 ++-- include/fmt/xchar.h | 5 +++-- src/fmt.cc | 1 + 13 files changed, 33 insertions(+), 26 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index 10c1eb8f44c17..d45b965bc51a6 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -8,7 +8,7 @@ #ifndef FMT_ARGS_H_ #define FMT_ARGS_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include // std::reference_wrapper # include // std::unique_ptr # include diff --git a/include/fmt/base.h b/include/fmt/base.h index a75f0bee89d6b..27cc293126550 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -15,11 +15,11 @@ # include // strlen #endif -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) // is also included transitively from . # include // std::byte # include // std::enable_if -#else +#elif !defined(FMT_MODULE) import std; #endif diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 77d0403246acb..3406a4a673f2f 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -8,7 +8,7 @@ #ifndef FMT_CHRONO_H_ #define FMT_CHRONO_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include # include # include // std::isfinite diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 9f69fcbb695b2..dabfb678ecffe 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -8,7 +8,7 @@ #ifndef FMT_COMPILE_H_ #define FMT_COMPILE_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include // std::back_inserter #endif diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 73f40f3d6bfe6..db6d74d4c95f3 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -8,16 +8,19 @@ #ifndef FMT_FORMAT_INL_H_ #define FMT_FORMAT_INL_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include # include # include #endif -#include // errno -#include -#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) -# include +#ifndef FMT_MODULE +# include // errno +# include + +# if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) +# include +# endif #endif #if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE) diff --git a/include/fmt/format.h b/include/fmt/format.h index fa8debc13b712..bfdb2e0e3fe8f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -38,7 +38,7 @@ # define FMT_REMOVE_TRANSITIVE_INCLUDES #endif -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include // std::signbit # include // uint32_t # include // std::memcpy @@ -57,14 +57,14 @@ // Checking FMT_CPLUSPLUS for warning suppression in MSVC. #if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L && \ - !defined(FMT_IMPORT_STD) + !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include // std::bit_cast #endif // libc++ supports string_view in pre-c++17. #if FMT_HAS_INCLUDE() && \ (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION)) -# ifndef FMT_IMPORT_STD +# if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include # endif # define FMT_USE_STRING_VIEW diff --git a/include/fmt/os.h b/include/fmt/os.h index fae18f166fb94..5462661a026a5 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -8,17 +8,19 @@ #ifndef FMT_OS_H_ #define FMT_OS_H_ -#include -#ifndef FMT_IMPORT_STD -# include -# include -# include // std::system_error +#ifndef FMT_MODULE +# include +# ifndef FMT_IMPORT_STD +# include +# include +# include // std::system_error +# endif #endif #include "format.h" #if defined __APPLE__ || defined(__FreeBSD__) -# if FMT_HAS_INCLUDE() +# if FMT_HAS_INCLUDE() && !defined(FMT_MODULE) # include // for LC_NUMERIC_MASK on OS X # endif #endif diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index f05e0dcde0359..0be26709dcd0d 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -8,7 +8,7 @@ #ifndef FMT_OSTREAM_H_ #define FMT_OSTREAM_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include // std::filebuf #endif diff --git a/include/fmt/printf.h b/include/fmt/printf.h index e6cd5c3d5d229..3b2b9b4be8b32 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -8,7 +8,7 @@ #ifndef FMT_PRINTF_H_ #define FMT_PRINTF_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include // std::max # include // std::numeric_limits #endif diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 49eede2a5abd7..624a6241559cb 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -8,7 +8,7 @@ #ifndef FMT_RANGES_H_ #define FMT_RANGES_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include # include # include diff --git a/include/fmt/std.h b/include/fmt/std.h index 99528514ebd14..5f1f403c41eeb 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -8,7 +8,7 @@ #ifndef FMT_STD_H_ #define FMT_STD_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include # include # include @@ -29,7 +29,7 @@ # include #endif -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) // Checking FMT_CPLUSPLUS for warning suppression in MSVC. # if FMT_CPLUSPLUS >= 201703L # if FMT_HAS_INCLUDE() diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index b8bb1359c0e35..31bdccdb97eed 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -8,7 +8,7 @@ #ifndef FMT_XCHAR_H_ #define FMT_XCHAR_H_ -#ifndef FMT_IMPORT_STD +#if !defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) # include #endif @@ -16,7 +16,8 @@ #include "format.h" #include "ranges.h" -#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) && \ + !defined(FMT_MODULE) # include #endif diff --git a/src/fmt.cc b/src/fmt.cc index b7e5ccd4c8132..890fd2572fae8 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -4,6 +4,7 @@ module; // to prevent attachment to this module. #ifndef FMT_IMPORT_STD # include +# include # include # include # include