diff options
author | 2021-09-18 02:02:58 +1000 | |
---|---|---|
committer | 2021-09-18 02:02:58 +1000 | |
commit | df8703523b002a44a9a5038bebb6397dad3bb42a (patch) | |
tree | d259e1a05e5bc9465de2ebfc06974721aa22141e | |
parent | 91a9904a84703d57cd649c9c66a4bea446298b2b (diff) |
util/strformat.h: Detect C++ standard > C++17 before doing weird stuff.
-rw-r--r-- | scripts/genie.lua | 3 | ||||
-rw-r--r-- | src/lib/util/strformat.cpp | 1 | ||||
-rw-r--r-- | src/lib/util/strformat.h | 26 |
3 files changed, 19 insertions, 11 deletions
diff --git a/scripts/genie.lua b/scripts/genie.lua index 173b0eee78e..4f443116ebb 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -497,6 +497,9 @@ configuration { "vs20*" } buildoptions { "/bigobj", } + buildoptions_cpp { + "/Zc:__cplusplus", + } flags { "ExtraWarnings", } diff --git a/src/lib/util/strformat.cpp b/src/lib/util/strformat.cpp index e173fb6aadf..cec14635e16 100644 --- a/src/lib/util/strformat.cpp +++ b/src/lib/util/strformat.cpp @@ -9,7 +9,6 @@ ***************************************************************************/ #include "strformat.h" -#include "vecstream.h" #include <iostream> #include <sstream> diff --git a/src/lib/util/strformat.h b/src/lib/util/strformat.h index 4714b9f5e71..e6d2ee0a0fe 100644 --- a/src/lib/util/strformat.h +++ b/src/lib/util/strformat.h @@ -597,10 +597,12 @@ private: str << int(std::make_signed_t<U>(value)); else if constexpr (!std::is_signed_v<U> || std::is_same_v<typename Stream::char_type, U>) str << std::make_signed_t<U>(value); - else if constexpr (std::is_invocable_v<decltype([] (auto &x, auto &y) -> decltype(x << y) { return x << y; }), Stream &, U const &>) - str << value; - else +#if __cplusplus > 201703L + else if constexpr (!std::is_invocable_v<decltype([] (auto &x, auto &y) -> decltype(x << y) { return x << y; }), Stream &, U const &>) str << std::make_signed_t<U>(value); +#endif + else + str << value; } template <typename U> @@ -610,10 +612,12 @@ private: str << unsigned(std::make_unsigned_t<U>(value)); else if constexpr (!std::is_unsigned_v<U> || std::is_same_v<typename Stream::char_type, U>) str << std::make_unsigned_t<U>(value); - else if constexpr (std::is_invocable_v<decltype([] (auto &x, auto &y) -> decltype(x << y) { return x << y; }), Stream &, U const &>) - str << value; - else +#if __cplusplus > 201703L + else if constexpr (!std::is_invocable_v<decltype([] (auto &x, auto &y) -> decltype(x << y) { return x << y; }), Stream &, U const &>) str << std::make_unsigned_t<U>(value); +#endif + else + str << value; } public: @@ -819,14 +823,16 @@ public: str << reinterpret_cast<void const *>(std::uintptr_t(value)); break; default: - if constexpr (std::is_invocable_v<decltype([] (auto &x, auto &y) -> decltype(x << y) { return x << y; }), Stream &, U const &>) +#if __cplusplus > 201703L + if constexpr (!std::is_invocable_v<decltype([] (auto &x, auto &y) -> decltype(x << y) { return x << y; }), Stream &, U const &>) { - str << value; + assert(false); // stream out operator not declared or declared deleted + str << '?'; } else +#endif { - assert(false); // stream out operator not declared or declared deleted - str << '?'; + str << value; } } } |