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

FMT_USE_USER_DEFINED_LITERALS has undefined behavior #541

Closed
bylee20 opened this issue Jul 11, 2017 · 2 comments
Closed

FMT_USE_USER_DEFINED_LITERALS has undefined behavior #541

bylee20 opened this issue Jul 11, 2017 · 2 comments

Comments

@bylee20
Copy link
Contributor

bylee20 commented Jul 11, 2017

#ifndef FMT_USE_USER_DEFINED_LITERALS
// All compilers which support UDLs also support variadic templates. This
// makes the fmt::literals implementation easier. However, an explicit check
// for variadic templates is added here just in case.
// For Intel's compiler both it and the system gcc/msc must support UDLs.
# define FMT_USE_USER_DEFINED_LITERALS \
   FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \
   (FMT_HAS_FEATURE(cxx_user_literals) || \
     (FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900) && \
   (!defined(FMT_ICC_VERSION) || FMT_ICC_VERSION >= 1500)
#endif

Here, FMT_USE_USER_DEFINED_LITERALS contains defined, and clang produces warning for this:

...\fmt\format.h:3932: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
#if FMT_USE_USER_DEFINED_LITERALS

This can be fixed, for instance:

#ifndef FMT_USE_USER_DEFINED_LITERALS
// All compilers which support UDLs also support variadic templates. This
// makes the fmt::literals implementation easier. However, an explicit check
// for variadic templates is added here just in case.
// For Intel's compiler both it and the system gcc/msc must support UDLs.
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \
    (FMT_HAS_FEATURE(cxx_user_literals) || \
      (FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900) && \
    (!defined(FMT_ICC_VERSION) || FMT_ICC_VERSION >= 1500)
#define FMT_USE_USER_DEFINED_LITERALS 1
#else
#define FMT_USE_USER_DEFINED_LITERALS 0
#endif
@vitaut
Copy link
Contributor

vitaut commented Jul 11, 2017

Good catch, could you by any chance submit a PR?

@bylee20
Copy link
Contributor Author

bylee20 commented Jul 12, 2017

@vitaut Sure: #542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants