Skip to content

Commit

Permalink
Optionally attach declarations to the global module rather than `mo…
Browse files Browse the repository at this point in the history
…dule 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.
  • Loading branch information
DanielaE committed Apr 16, 2023
1 parent 28757cd commit d4dcf38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ inline auto vsprintf(
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
-> std::basic_string<Char> {
auto buf = basic_memory_buffer<Char>();
vprintf(buf, detail::to_string_view(fmt), args);
detail::vprintf(buf, detail::to_string_view(fmt), args);
return to_string(buf);
}

Expand All @@ -626,7 +626,7 @@ inline auto vfprintf(
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
-> int {
auto buf = basic_memory_buffer<Char>();
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
Expand Down
8 changes: 8 additions & 0 deletions src/fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down

0 comments on commit d4dcf38

Please sign in to comment.