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
7 changes: 5 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ FMT_END_NAMESPACE

#ifndef FMT_USE_USER_DEFINED_LITERALS
// EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs.
# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION >= 407 || \
//
// 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 >= 409 || \
FMT_MSC_VERSION >= 1900) && \
(!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480)
# define FMT_USE_USER_DEFINED_LITERALS 1
Expand Down Expand Up @@ -4428,7 +4431,7 @@ template <detail_exported::fixed_string Str> constexpr auto operator""_a() {
return detail::udl_arg<char_t, sizeof(Str.data) / sizeof(char_t), Str>();
}
# else
constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg<char> {
constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg<char> {
return {s};
}
# endif
Expand Down
12 changes: 10 additions & 2 deletions test/compile-error-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ set(CMAKE_REQUIRED_FLAGS )
if (NOT SUPPORTS_USER_DEFINED_LITERALS)
set (SUPPORTS_USER_DEFINED_LITERALS OFF)
endif ()
if (SUPPORTS_USER_DEFINED_LITERALS AND CMAKE_COMPILER_IS_GNUCXX)
# GCC before 4.9 is not supported for user-defined literals as it requires an
# invalid syntax in their definition.
set (SUPPORTS_USER_DEFINED_LITERALS
$<IF:$<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,4.9.0>,OFF,ON>)
endif()

# Make sure that compiler features detected in the header
# match the features detected in CMake.
Expand Down Expand Up @@ -222,13 +228,15 @@ if (CMAKE_CXX_STANDARD GREATER_EQUAL 20)

# Compile-time argument name check
expect_compile(format-string-name "
#if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_ARGS
#if defined(FMT_HAS_CONSTEVAL) && \
FMT_USE_USER_DEFINED_LITERALS && FMT_USE_NONTYPE_TEMPLATE_ARGS
using namespace fmt::literals;
fmt::print(\"{foo}\", \"foo\"_a=42);
#endif
")
expect_compile(format-string-name-error "
#if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_ARGS
#if defined(FMT_HAS_CONSTEVAL) && \
FMT_USE_USER_DEFINED_LITERALS && FMT_USE_NONTYPE_TEMPLATE_ARGS
using namespace fmt::literals;
fmt::print(\"{foo}\", \"bar\"_a=42);
#else
Expand Down