Skip to content

Commit

Permalink
fix __cplusplus check for MSVC
Browse files Browse the repository at this point in the history
Because of an MSVC bug, __cplusplus is always 199711L. Use _MSVC_LANG
which gets set properly.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Jan 4, 2023
1 parent f515799 commit b31b4ab
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ class ValueType : public Value {
}

// Check for integer overflow.
#if __cplusplus >= 201703L
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
if constexpr (std::is_signed_v<I> == std::is_signed_v<decltype(a)>) {
#else
if (std::is_signed<I>::value == std::is_signed<decltype(a)>::value) {
Expand All @@ -1281,13 +1281,13 @@ class ValueType : public Value {
if (imax < b || a < imin || imax < a) {
return 0;
}
#if __cplusplus >= 201703L
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
} else if constexpr (std::is_signed_v<I>) {
#else
} else if (std::is_signed<I>::value) {
#endif
// conversion is from unsigned to signed
#if __cplusplus >= 201402L
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
const auto imax = static_cast<std::make_unsigned_t<I>>(std::numeric_limits<I>::max());
#else
const auto imax = static_cast<typename std::make_unsigned<I>::type>(std::numeric_limits<I>::max());
Expand All @@ -1302,7 +1302,7 @@ class ValueType : public Value {
return 0;
}
// Inputs are not negative so convert them to unsigned.
#if __cplusplus >= 201402L
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
const auto a_u = static_cast<std::make_unsigned_t<decltype(a)>>(a);
const auto b_u = static_cast<std::make_unsigned_t<decltype(b)>>(b);
#else
Expand Down

0 comments on commit b31b4ab

Please sign in to comment.