Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"conditional expression is constant" warnings due to using if where if constexpr is appropriate #23

Open
VioletGiraffe opened this issue Feb 21, 2023 · 2 comments

Comments

@VioletGiraffe
Copy link

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))

@Tessil
Copy link
Owner

Tessil commented Feb 21, 2023

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

@VioletGiraffe
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants