Fix compile-time checks for user-defined types (#1292)

This commit is contained in:
Victor Zverovich 2019-08-31 08:35:38 -07:00
parent d1dd9d5327
commit 422e7b9d70
3 changed files with 8 additions and 1 deletions

View File

@ -207,6 +207,8 @@ template <typename T>
using remove_reference_t = typename std::remove_reference<T>::type; using remove_reference_t = typename std::remove_reference<T>::type;
template <typename T> template <typename T>
using remove_const_t = typename std::remove_const<T>::type; using remove_const_t = typename std::remove_const<T>::type;
template <typename T>
using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
struct monostate {}; struct monostate {};

View File

@ -3466,7 +3466,7 @@ template <typename Char, Char... CHARS> class udl_formatter {
std::basic_string<Char> operator()(Args&&... args) const { std::basic_string<Char> operator()(Args&&... args) const {
FMT_CONSTEXPR_DECL Char s[] = {CHARS..., '\0'}; FMT_CONSTEXPR_DECL Char s[] = {CHARS..., '\0'};
FMT_CONSTEXPR_DECL bool invalid_format = FMT_CONSTEXPR_DECL bool invalid_format =
do_check_format_string<Char, error_handler, Args...>( do_check_format_string<Char, error_handler, remove_cvref_t<Args>...>(
basic_string_view<Char>(s, sizeof...(CHARS))); basic_string_view<Char>(s, sizeof...(CHARS)));
(void)invalid_format; (void)invalid_format;
return format(s, std::forward<Args>(args)...); return format(s, std::forward<Args>(args)...);

View File

@ -1894,6 +1894,11 @@ TEST(FormatTest, UdlTemplate) {
EXPECT_EQ("foo", "foo"_format()); EXPECT_EQ("foo", "foo"_format());
EXPECT_EQ(" 42", "{0:10}"_format(42)); EXPECT_EQ(" 42", "{0:10}"_format(42));
} }
TEST(FormatTest, UdlPassUserDefinedObjectAsLvalue) {
Date date(2015, 10, 21);
EXPECT_EQ("2015-10-21", "{}"_format(date));
}
#endif // FMT_USE_USER_DEFINED_LITERALS #endif // FMT_USE_USER_DEFINED_LITERALS
enum TestEnum { A }; enum TestEnum { A };