Make compile-time checks in format_to handle references
This commit is contained in:
parent
58e6c84f5a
commit
1e8493196e
@ -1460,7 +1460,7 @@ make_args_checked(const S& format_str,
|
||||
all_true<(!std::is_base_of<view, remove_reference_t<Args>>::value ||
|
||||
!std::is_reference<Args>::value)...>::value,
|
||||
"passing views as lvalues is disallowed");
|
||||
check_format_string<remove_const_t<remove_reference_t<Args>>...>(format_str);
|
||||
check_format_string<Args...>(format_str);
|
||||
return {args...};
|
||||
}
|
||||
|
||||
|
@ -2641,10 +2641,9 @@ FMT_CONSTEXPR bool do_check_format_string(basic_string_view<Char> s,
|
||||
template <typename... Args, typename S,
|
||||
enable_if_t<(is_compile_string<S>::value), int>>
|
||||
void check_format_string(S format_str) {
|
||||
FMT_CONSTEXPR_DECL bool invalid_format =
|
||||
internal::do_check_format_string<typename S::char_type,
|
||||
internal::error_handler, Args...>(
|
||||
to_string_view(format_str));
|
||||
FMT_CONSTEXPR_DECL bool invalid_format = internal::do_check_format_string<
|
||||
typename S::char_type, internal::error_handler,
|
||||
remove_const_t<remove_reference_t<Args>>...>(to_string_view(format_str));
|
||||
(void)invalid_format;
|
||||
}
|
||||
|
||||
|
@ -1859,6 +1859,8 @@ TEST(FormatTest, CustomFormatCompileTimeString) {
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), Answer()));
|
||||
Answer answer;
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), answer));
|
||||
char buf[10] = {};
|
||||
fmt::format_to(buf, FMT_STRING("{}"), answer);
|
||||
const Answer const_answer = Answer();
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), const_answer));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user