Skip to content

Commit

Permalink
Disable MSVC warning 4127 locally instead of globally
Browse files Browse the repository at this point in the history
  • Loading branch information
zann1x committed Mar 6, 2024
1 parent e62deaa commit 440d949
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 0 additions & 4 deletions include/soci/soci-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
//base class must have dll interface
#pragma warning(disable:4251 4275)

// As long as we don't require C++17, we must disable the warning
// "conditional expression is constant"
#pragma warning(disable:4127)

// Define if you have the vsnprintf variants.
#if _MSC_VER < 1500
# define vsnprintf _vsnprintf
Expand Down
10 changes: 9 additions & 1 deletion include/soci/type-holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "soci/error.h"
#include "soci/soci-backend.h"
#include "soci/soci-platform.h"
#include "soci/soci-types.h"

#include <cstdint>
Expand Down Expand Up @@ -89,11 +88,20 @@ struct soci_cast<
uintmax_t t_max = static_cast<uintmax_t>((std::numeric_limits<T>::max)());
uintmax_t u_max = static_cast<uintmax_t>((std::numeric_limits<U>::max)());

#ifdef _MSC_VER
// As long as we don't require C++17, we must disable the warning
// "conditional expression is constant" as it can give false positives here.
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if ((t_min > u_min && val < static_cast<U>(t_min)) ||
(t_max < u_max && val > static_cast<U>(t_max)))
{
throw std::bad_cast();
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif

return static_cast<T>(val);
}
Expand Down

0 comments on commit 440d949

Please sign in to comment.