From b84b3bed47ebcdd4c0c9fec9f5c82a766c0ad3a3 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 23 Aug 2023 22:25:34 -0400 Subject: [PATCH] Avoid a space in the UDL definition except on GCC before 4.9 Clang 18 has grown a warning about the space being deprecated which is enabled by default in their nightly binaries. However GCC before 4.9 will reject the UDL definition unless there is a space there, so we need to keep the space conditionally for it. --- include/fmt/format.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9b4f7357..9909e19f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -152,12 +152,21 @@ FMT_END_NAMESPACE #ifndef FMT_USE_USER_DEFINED_LITERALS // EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs. +// +// GCC before 4.9 requires a space in `operator"" _a` which is invalid in later +// compiler versions. # if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION >= 407 || \ FMT_MSC_VERSION >= 1900) && \ (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480) # define FMT_USE_USER_DEFINED_LITERALS 1 +# if FMT_GCC_VERSION > 0 && FMT_GCC_VERSION < 409 +# define FMT_WHITESPACE_IN_USER_DEFINED_LITERALS 1 +# else +# define FMT_WHITESPACE_IN_USER_DEFINED_LITERALS 0 +# endif # else # define FMT_USE_USER_DEFINED_LITERALS 0 +# define FMT_WHITESPACE_IN_USER_DEFINED_LITERALS 0 # endif #endif @@ -4427,10 +4436,14 @@ template constexpr auto operator""_a() { using char_t = remove_cvref_t; return detail::udl_arg(); } -# else +# elif FMT_WHITESPACE_IN_USER_DEFINED_LITERALS constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg { return {s}; } +# else +constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg { + return {s}; +} # endif } // namespace literals #endif // FMT_USE_USER_DEFINED_LITERALS