From 06c005b7b0bba63d4d7a36cd28e144cdf17f6403 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 27 Jan 2019 09:05:50 -0800 Subject: [PATCH] Clarify that compile-time checks don't support named arguments --- doc/api.rst | 3 +++ include/fmt/format.h | 14 +++++++++++++- test/format-test.cc | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 33a4f6d2..bf8dbbe6 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -56,6 +56,8 @@ Named arguments .. doxygenfunction:: fmt::arg(string_view, const T&) +Named arguments are not supported in compile-time checks at the moment. + Argument lists -------------- @@ -92,6 +94,7 @@ string checks, output iterator and user-defined type support. Compile-time format string checks --------------------------------- +.. doxygendefine:: FMT_STRING .. doxygendefine:: fmt Formatting user-defined types diff --git a/include/fmt/format.h b/include/fmt/format.h index 1c05b0ea..4be16c05 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2117,7 +2117,9 @@ class format_string_checker { context_.check_arg_id(id); check_arg_id(); } - FMT_CONSTEXPR void on_arg_id(basic_string_view) {} + FMT_CONSTEXPR void on_arg_id(basic_string_view) { + on_error("compile-time checks don't support named arguments"); + } FMT_CONSTEXPR void on_replacement_field(const Char*) {} @@ -3495,6 +3497,16 @@ inline internal::udl_arg operator"" _a(const wchar_t* s, std::size_t) { #endif // FMT_USE_USER_DEFINED_LITERALS FMT_END_NAMESPACE +/** + \rst + Constructs a compile-time format string. + + **Example**:: + + // A compile-time error because 'd' is an invalid specifier for strings. + std::string s = format(FMT_STRING("{:d}"), "foo"); + \endrst + */ #define FMT_STRING(s) \ [] { \ struct str : fmt::compile_string { \ diff --git a/test/format-test.cc b/test/format-test.cc index 14022468..84142ffc 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2357,7 +2357,8 @@ TEST(FormatTest, FormatStringErrors) { EXPECT_ERROR("{:d}", "invalid type specifier", std::string); EXPECT_ERROR("{:s}", "invalid type specifier", void*); # endif - EXPECT_ERROR("{foo", "missing '}' in format string", int); + EXPECT_ERROR("{foo", + "compile-time checks don't support named arguments", int); EXPECT_ERROR_NOARGS("{10000000000}", "number is too big"); EXPECT_ERROR_NOARGS("{0x}", "invalid format string"); EXPECT_ERROR_NOARGS("{-}", "invalid format string");