The following code should be valid, but cppcheck complains no matter of if with constexpr or a regular if:
template <int b> int f(int a) { if constexpr (b >= 0) { return a << b; } else { return a << -b; } } int g() { return f<1>(2) }
Yields both in my personal code and in http://cppcheck.net/demo/:
[test.cpp:7]: (error) Shifting by a negative value is undefined behaviour
CPPCheck should take into account the branching over the right operand (here, b) of the << operator.
b
<<
Sadly this is the duplicated post, please visit the original post
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/13326
Log in to post a comment.
The following code should be valid, but cppcheck complains no matter of if with constexpr or a regular if:
Yields both in my personal code and in http://cppcheck.net/demo/:
CPPCheck should take into account the branching over the right operand (here,
b
) of the<<
operator.Sadly this is the duplicated post, please visit the original post
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/13326