Skip to content

Commit

Permalink
Remove invalid_arg_index
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 22, 2023
1 parent d0652d2 commit 6fe8954
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
16 changes: 7 additions & 9 deletions include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,18 @@ constexpr auto compile_format_string(S format_str) {
} else if constexpr (arg_id_result.arg_id.kind == arg_id_kind::name) {
constexpr auto arg_index =
get_arg_index_by_name(arg_id_result.arg_id.val.name, Args{});
if constexpr (arg_index != invalid_arg_index) {
if constexpr (arg_index >= 0) {
constexpr auto next_id =
ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
return parse_replacement_field_then_tail<
decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
arg_index, next_id>(format_str);
} else {
if constexpr (c == '}') {
return parse_tail<Args, arg_id_end_pos + 1, ID>(
runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
format_str);
} else if constexpr (c == ':') {
return unknown_format(); // no type info for specs parsing
}
} else if constexpr (c == '}') {
return parse_tail<Args, arg_id_end_pos + 1, ID>(
runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
format_str);
} else if constexpr (c == ':') {
return unknown_format(); // no type info for specs parsing
}
}
}
Expand Down
14 changes: 3 additions & 11 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@
# endif
#endif

#if defined __cpp_inline_variables && __cpp_inline_variables >= 201606L
# define FMT_INLINE_VARIABLE inline
#else
# define FMT_INLINE_VARIABLE
#endif

// Enable minimal optimizations for more compact code in debug mode.
FMT_GCC_PRAGMA("GCC push_options")
#if !defined(__OPTIMIZE__) && !defined(__NVCOMPILER) && !defined(__LCC__) && \
Expand Down Expand Up @@ -2543,8 +2537,6 @@ FMT_CONSTEXPR auto check_char_specs(const format_specs<Char>& specs) -> bool {
return true;
}

constexpr FMT_INLINE_VARIABLE int invalid_arg_index = -1;

#if FMT_USE_NONTYPE_TEMPLATE_ARGS
template <int N, typename T, typename... Args, typename Char>
constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
Expand All @@ -2554,7 +2546,7 @@ constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
if constexpr (sizeof...(Args) > 0)
return get_arg_index_by_name<N + 1, Args...>(name);
(void)name; // Workaround an MSVC bug about "unused" parameter.
return invalid_arg_index;
return -1;
}
#endif

Expand All @@ -2565,7 +2557,7 @@ FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
return get_arg_index_by_name<0, Args...>(name);
#endif
(void)name;
return invalid_arg_index;
return -1;
}

template <typename Char, typename... Args> class format_string_checker {
Expand Down Expand Up @@ -2598,7 +2590,7 @@ template <typename Char, typename... Args> class format_string_checker {
FMT_CONSTEXPR auto on_arg_id(basic_string_view<Char> id) -> int {
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
auto index = get_arg_index_by_name<Args...>(id);
if (index == invalid_arg_index) on_error("named argument is not found");
if (index < 0) on_error("named argument is not found");
return index;
#else
(void)id;
Expand Down
6 changes: 6 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
# define FMT_END_DETAIL_NAMESPACE }
#endif

#if defined __cpp_inline_variables && __cpp_inline_variables >= 201606L
# define FMT_INLINE_VARIABLE inline
#else
# define FMT_INLINE_VARIABLE
#endif

#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
# define FMT_FALLTHROUGH [[fallthrough]]
#elif defined(__clang__)
Expand Down

0 comments on commit 6fe8954

Please sign in to comment.