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

Make MSVC use [[nodiscard]] #2615

Merged
merged 3 commits into from
Nov 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@
# define FMT_HAS_CPP_ATTRIBUTE(x) 0
#endif

#ifdef _MSVC_LANG
# define FMT_CPLUSPLUS _MSVC_LANG
#else
# define FMT_CPLUSPLUS __cplusplus
#endif
Comment on lines +85 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here? Doesn't MSVC use the standard __cplusplus macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Zc:__cplusplus enables updated C++ macro. By default __cplusplus is defined to some ancient value.

As I read in MSVC STL chat, the reason for this default behavior is the compatibility with some open-source code, in which higher __cplusplus values enable not only legitimate C++ features, but also gcc extensions.

You already had _MSVC_LANG for [[fallthrough]], I'm just propagating it a bit further.


#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
(__cplusplus >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
(FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))

#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
(__cplusplus >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
(FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
AlexGuteniev marked this conversation as resolved.
Show resolved Hide resolved

// Check if relaxed C++14 constexpr is supported.
// GCC doesn't allow throw in constexpr until version 6 (bug 67371).
Expand Down Expand Up @@ -180,8 +186,7 @@
# else
# define FMT_FALLTHROUGH
# endif
#elif FMT_HAS_CPP17_ATTRIBUTE(fallthrough) || \
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
#elif FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
# define FMT_FALLTHROUGH [[fallthrough]]
#else
# define FMT_FALLTHROUGH
Expand Down