Skip to content

Commit

Permalink
Fix preprocessor warnings about undefined _MSVC_LANG
Browse files Browse the repository at this point in the history
Stricter compiler/settings, such as found during a build
on FreeBSD with clang 14, issue warnings of the kind below.

/usr/local/include/exiv2/value.hpp:1272:31: warning: '_MSVC_LANG' is not defined, evaluates to 0 [-Wundef]

Fix: Guard use of _MSVC_LANG by a check.

Personally, I found that MSVC has several feature-specific
checks in predefined macros which might allow for one
standards-based check that matches GCC/clang/MSVC rather than the
split check for C++ standard and MSVC language version settings.

See https://en.cppreference.com/w/cpp/feature_test

I am not building Exiv2 on MSVC, so I cannot test/suggest
anything here.

(cherry picked from commit 901e8ba)
  • Loading branch information
mandree authored and neheb committed Jul 3, 2023
1 parent e892ca4 commit 512223f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions include/exiv2/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ struct ContainerStorage {
using iterator = typename container::iterator;
using const_iterator = typename container::const_iterator;

#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
using value_type = std::remove_cv_t<typename container::value_type>;
#else
using value_type = typename std::remove_cv<typename container::value_type>::type;
Expand Down Expand Up @@ -320,7 +320,7 @@ struct ContainerStorage {
*/
template <typename storage_type>
struct PtrSliceStorage {
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
using value_type = std::remove_cv_t<std::remove_pointer_t<storage_type>>;
#else
using value_type = typename std::remove_cv<typename std::remove_pointer<storage_type>::type>::type;
Expand Down Expand Up @@ -423,7 +423,7 @@ struct Slice : public Internal::MutableSliceBase<Internal::ContainerStorage, con
using iterator = typename container::iterator;
using const_iterator = typename container::const_iterator;

#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
using value_type = std::remove_cv_t<typename container::value_type>;
#else
using value_type = typename std::remove_cv<typename container::value_type>::type;
Expand Down Expand Up @@ -460,7 +460,7 @@ struct Slice<const container> : public Internal::ConstSliceBase<Internal::Contai
using iterator = typename container::iterator;
using const_iterator = typename container::const_iterator;

#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
using value_type = std::remove_cv_t<typename container::value_type>;
#else
using value_type = typename std::remove_cv<typename container::value_type>::type;
Expand Down
4 changes: 2 additions & 2 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ class ValueType : public Value {
} else if (std::is_signed<I>::value) {
#endif
// conversion is from unsigned to signed
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_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 @@ -1269,7 +1269,7 @@ class ValueType : public Value {
return 0;
}
// Inputs are not negative so convert them to unsigned.
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_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 512223f

Please sign in to comment.