Skip to content

Commit

Permalink
Workaround msvc constexpr issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jun 1, 2021
1 parent 8c1b22b commit ed2a637
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
// GCC doesn't allow throw in constexpr until version 6 (bug 67371).
#ifndef FMT_USE_CONSTEXPR
# define FMT_USE_CONSTEXPR \
(FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1920 || \
(FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \
(FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) && \
!FMT_NVCC && !FMT_ICC_VERSION
#endif
Expand Down Expand Up @@ -1581,7 +1581,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
FMT_CONSTEXPR auto arg(basic_string_view<char_type> name) -> format_arg {
return args_.get(name);
}
auto arg_id(basic_string_view<char_type> name) -> int {
FMT_CONSTEXPR auto arg_id(basic_string_view<char_type> name) -> int {
return args_.get_id(name);
}
auto args() const -> const basic_format_args<basic_format_context>& {
Expand Down Expand Up @@ -2179,7 +2179,7 @@ FMT_CONSTEXPR auto parse_width(const Char* begin, const Char* end,
handler.on_dynamic_width(id);
}
FMT_CONSTEXPR void on_error(const char* message) {
handler.on_error(message);
if (message) handler.on_error(message);
}
};

Expand Down Expand Up @@ -2209,7 +2209,7 @@ FMT_CONSTEXPR auto parse_precision(const Char* begin, const Char* end,
handler.on_dynamic_precision(id);
}
FMT_CONSTEXPR void on_error(const char* message) {
handler.on_error(message);
if (message) handler.on_error(message);
}
};

Expand Down Expand Up @@ -2310,7 +2310,7 @@ FMT_CONSTEXPR auto parse_replacement_field(const Char* begin, const Char* end,
arg_id = handler.on_arg_id(id);
}
FMT_CONSTEXPR void on_error(const char* message) {
handler.on_error(message);
if (message) handler.on_error(message);
}
};

Expand Down
8 changes: 5 additions & 3 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2659,9 +2659,11 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
context.advance_to(write<Char>(context.out(), text));
}

int on_arg_id() { return parse_context.next_arg_id(); }
int on_arg_id(int id) { return parse_context.check_arg_id(id), id; }
int on_arg_id(basic_string_view<Char> id) {
FMT_CONSTEXPR int on_arg_id() { return parse_context.next_arg_id(); }
FMT_CONSTEXPR int on_arg_id(int id) {
return parse_context.check_arg_id(id), id;
}
FMT_CONSTEXPR int on_arg_id(basic_string_view<Char> id) {
int arg_id = context.arg_id(id);
if (arg_id < 0) on_error("argument not found");
return arg_id;
Expand Down
9 changes: 6 additions & 3 deletions test/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ struct scan_handler : error_handler {
scan_ctx_.advance_to(it + size);
}

int on_arg_id() { return on_arg_id(next_arg_id_++); }
int on_arg_id(int id) {
FMT_CONSTEXPR int on_arg_id() { return on_arg_id(next_arg_id_++); }
FMT_CONSTEXPR int on_arg_id(int id) {
if (id >= args_.size) on_error("argument index out of range");
arg_ = args_.data[id];
return id;
}
int on_arg_id(string_view) { return on_error("invalid format"), 0; }
FMT_CONSTEXPR int on_arg_id(string_view id) {
if (id.data()) on_error("invalid format");
return 0;
}

void on_replacement_field(int, const char*) {
auto it = scan_ctx_.begin(), end = scan_ctx_.end();
Expand Down

0 comments on commit ed2a637

Please sign in to comment.