Skip to content

Commit d4dcf38

Browse files
committed
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.
1 parent 28757cd commit d4dcf38

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/fmt/printf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ inline auto vsprintf(
599599
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
600600
-> std::basic_string<Char> {
601601
auto buf = basic_memory_buffer<Char>();
602-
vprintf(buf, detail::to_string_view(fmt), args);
602+
detail::vprintf(buf, detail::to_string_view(fmt), args);
603603
return to_string(buf);
604604
}
605605

@@ -626,7 +626,7 @@ inline auto vfprintf(
626626
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
627627
-> int {
628628
auto buf = basic_memory_buffer<Char>();
629-
vprintf(buf, detail::to_string_view(fmt), args);
629+
detail::vprintf(buf, detail::to_string_view(fmt), args);
630630
size_t size = buf.size();
631631
return std::fwrite(buf.data(), sizeof(Char), size, f) < size
632632
? -1

src/fmt.cc

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export module fmt;
7373
export {
7474
// All library-provided declarations and definitions must be in the module
7575
// purview to be exported.
76+
#ifdef FMT_ATTACH_TO_GLOBAL_MODULE
77+
extern "C++" {
78+
#endif
79+
7680
#include "fmt/args.h"
7781
#include "fmt/chrono.h"
7882
#include "fmt/color.h"
@@ -83,6 +87,10 @@ export module fmt;
8387
#include "fmt/xchar.h"
8488
#include "fmt/std.h"
8589

90+
#ifdef FMT_ATTACH_TO_GLOBAL_MODULE
91+
}
92+
#endif
93+
8694
// gcc doesn't yet implement private module fragments
8795
#if !FMT_GCC_VERSION
8896
module : private;

0 commit comments

Comments
 (0)