Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a space in the UDL definition #3610

Merged
merged 9 commits into from
Sep 18, 2023
15 changes: 14 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
danakj marked this conversation as resolved.
Show resolved Hide resolved
# else
# define FMT_USE_USER_DEFINED_LITERALS 0
# define FMT_WHITESPACE_IN_USER_DEFINED_LITERALS 0
# endif
#endif

Expand Down Expand Up @@ -4427,10 +4436,14 @@ template <detail_exported::fixed_string Str> constexpr auto operator""_a() {
using char_t = remove_cvref_t<decltype(Str.data[0])>;
return detail::udl_arg<char_t, sizeof(Str.data) / sizeof(char_t), Str>();
}
# else
# elif FMT_WHITESPACE_IN_USER_DEFINED_LITERALS
constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg<char> {
return {s};
}
# else
constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg<char> {
return {s};
}
# endif
} // namespace literals
#endif // FMT_USE_USER_DEFINED_LITERALS
Expand Down