From d4dcf3855d5c98fcd930d5147db560efad404460 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Sun, 16 Apr 2023 15:52:55 +0200 Subject: [PATCH] Optionally attach declarations to the `global module` rather than `module fmt` This allows coexistence with TUs that use {fmt} through #include without duplicating declarations, definitions, linker symbols, and object code. This unveiled clashes with name 'vfprintf' from `stdio.h`. Drive-by fix using qualified name lookup. --- include/fmt/printf.h | 4 ++-- src/fmt.cc | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 25e93bb31d217..554715e9bb2be 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -599,7 +599,7 @@ inline auto vsprintf( basic_format_args>> args) -> std::basic_string { auto buf = basic_memory_buffer(); - vprintf(buf, detail::to_string_view(fmt), args); + detail::vprintf(buf, detail::to_string_view(fmt), args); return to_string(buf); } @@ -626,7 +626,7 @@ inline auto vfprintf( basic_format_args>> args) -> int { auto buf = basic_memory_buffer(); - vprintf(buf, detail::to_string_view(fmt), args); + detail::vprintf(buf, detail::to_string_view(fmt), args); size_t size = buf.size(); return std::fwrite(buf.data(), sizeof(Char), size, f) < size ? -1 diff --git a/src/fmt.cc b/src/fmt.cc index d588764a4868c..f47fae41fb9b1 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -73,6 +73,10 @@ export module fmt; export { // All library-provided declarations and definitions must be in the module // purview to be exported. +#ifdef FMT_ATTACH_TO_GLOBAL_MODULE +extern "C++" { +#endif + #include "fmt/args.h" #include "fmt/chrono.h" #include "fmt/color.h" @@ -83,6 +87,10 @@ export module fmt; #include "fmt/xchar.h" #include "fmt/std.h" +#ifdef FMT_ATTACH_TO_GLOBAL_MODULE +} +#endif + // gcc doesn't yet implement private module fragments #if !FMT_GCC_VERSION module : private;