dcleblanc / SafeInt

SafeInt is a class library for C++ that manages integer overflows.
MIT License
216 stars 37 forks source link

Issues with std::numeric_limits<T>::min/max if WinDef.h is included without #define NOMINMAX #51

Open raphgianotti opened 1 year ago

raphgianotti commented 1 year ago

This discussion goes over the issue: https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax

I have tested locally and simply enclosing the calls to std::numeric_limits::min/max in parenthesis completely fixes the issues, while changing no functionality on the library, and improves its compatibility with code that includes WinDef.h (which is automatically included with Windows.h).

Example of it on SafeInt.hpp:2536:

From this:

            if( tmp > std::numeric_limits< std::int32_t >::max() ||
                tmp < std::numeric_limits< std::int32_t >::min() )

To this:

            if( tmp > (std::numeric_limits< std::int32_t >::max)() ||
                tmp < (std::numeric_limits< std::int32_t >::min)() )