diff --git a/include/fmt/format.h b/include/fmt/format.h index 98f1f249..2bf9b571 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -79,6 +79,10 @@ # endif #endif +#ifdef __clang__ +# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) +#endif + #if defined(__INTEL_COMPILER) # define FMT_ICC_VERSION __INTEL_COMPILER #elif defined(__ICL) @@ -88,6 +92,7 @@ #if defined(__clang__) && !defined(FMT_ICC_VERSION) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +# pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template" # pragma clang diagnostic ignored "-Wpadded" #endif @@ -185,6 +190,13 @@ # endif #endif +#if FMT_USE_USER_DEFINED_LITERALS && \ + (FMT_GCC_VERSION >= 600 || FMT_CLANG_VERSION >= 304) +# define FMT_UDL_TEMPLATE 1 +#else +# define FMT_UDL_TEMPLATE 0 +#endif + #ifndef FMT_ASSERT # define FMT_ASSERT(condition, message) assert((condition) && message) #endif @@ -3839,10 +3851,27 @@ operator"" _a(const char *s, std::size_t) { return {s}; } inline internal::UdlArg operator"" _a(const wchar_t *s, std::size_t) { return {s}; } +# if FMT_UDL_TEMPLATE +template +struct udl_formatter { + template + std::string operator()(const Args &... args) const { + const Char s[] = {CHARS...}; + // TODO + return s; + } +}; + +template +constexpr auto operator""_format() { + return udl_formatter(); +} +# endif } // inline namespace literals } // namespace fmt #endif // FMT_USE_USER_DEFINED_LITERALS + #ifdef FMT_HEADER_ONLY # define FMT_FUNC inline # include "format.cc" diff --git a/test/format-test.cc b/test/format-test.cc index 5d90b17f..08871e86 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1812,3 +1812,9 @@ TEST(FormatTest, ConstexprParseFormatString) { static_assert(parse_string("{foo}"), ""); static_assert(parse_string("{:}"), ""); } + +#if FMT_UDL_TEMPLATE +TEST(FormatTest, UdlTemplate) { + EXPECT_EQ("foo", "foo"_format()); +} +#endif