"conditional expression is constant" warnings due to using `if` where `if constexpr` is appropriate
VioletGiraffe opened this issue · 2 comments
There are 3 places in sparse_hash.h where MSVC gives the aforementioned warning (with /W4 level which is my default). All the conditions are indeed purely compile-time and should be replaced with constexpr
. Will you accept a pull request if I fix this?
For example: if (sizeof(unsigned int) == sizeof(std::uint32_t))
Yes, that would be an useful fix. The lib was developed before C++17 if constexpr
and I just used a simple if
to avoid std::enable_if
at the time.
Could you keep the C++11/14 backward compatibility and only enable the change for C++17 and above (I should start to think to remove support for < C++17 though...)?
Thanks
That's a good point, I didn't consider the need to support older compilers. In that case, I think, either #ifdef
is required, or the old trick with bool const_condition(bool cond) { return cond; }
- this will not generate the warning in debug, and should still be optimized away in release.