Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FMT_FORCE_FALLBACK_FILE to force the use of fallback_file #4009

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ template <typename F> class fallback_file : public file_base<F> {
}
};

#ifndef FMT_FORCE_FALLBACK_FILE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to FMT_USE_FALLBACK_FILE for consistency with other similar macros and make it take value 0 or 1, see e.g.

fmt/include/fmt/base.h

Lines 158 to 164 in a5c1b5d

#ifdef FMT_USE_CONCEPTS
// Use the provided definition.
#elif defined(__cpp_concepts)
# define FMT_USE_CONCEPTS 1
#else
# define FMT_USE_CONCEPTS 0
#endif

template <typename F, FMT_ENABLE_IF(sizeof(F::_p) != 0)>
auto get_file(F* f, int) -> apple_file<F> {
return f;
Expand All @@ -1608,6 +1609,8 @@ template <typename F, FMT_ENABLE_IF(sizeof(F::_IO_read_ptr) != 0)>
inline auto get_file(F* f, int) -> glibc_file<F> {
return f;
}
#endif

inline auto get_file(FILE* f, ...) -> fallback_file<FILE> { return f; }

using file_ref = decltype(get_file(static_cast<FILE*>(nullptr), 0));
Expand Down
2 changes: 2 additions & 0 deletions test/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class string_scan_buffer final : public scan_buffer {

class file_scan_buffer final : public scan_buffer {
private:
#ifndef FMT_FORCE_FALLBACK_FILE
template <typename F, FMT_ENABLE_IF(sizeof(F::_IO_read_ptr) != 0)>
static auto get_file(F* f, int) -> glibc_file<F> {
return f;
Expand All @@ -161,6 +162,7 @@ class file_scan_buffer final : public scan_buffer {
static auto get_file(F* f, int) -> apple_file<F> {
return f;
}
#endif
static auto get_file(FILE* f, ...) -> fallback_file<FILE> { return f; }

decltype(get_file(static_cast<FILE*>(nullptr), 0)) file_;
Expand Down
Loading