Error for static_assert
2 1.76.1 duplicateExpression style Same expression on both sides of '<'. Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
Error for zerodiv
2 1.76.1 zerodiv error Division by zero. Division by zero.
Does anyone know if this is a false positive or if not how I can change my code to not get errors.
Last edit: Nikolai 2016-12-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It seems to me that you instantiate the template method with ui8Size=0 somewhere. Then ui8Size is replaced with 0.. so "0 < ui8Size" becomes "0 < 0" and "% ui8Size" becomes "% 0".
So the warnings are technically correct.
I don't want that we report duplicateExpression for this code. This is a false positive. I believe there are tickets about this already.
About the zero division. If you instantiate the method with 0 then you get "% 0" that means division by zero. I don't see why that would be a false positive. So I believe it's only a false positive if you don't instantiate with 0.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Daniel,
thank you for the quick response. I was on holidays and didn't have access to the codebase.
The point with static_assert is, it should never reach the line, ui8WindowIndex = ( ui8WindowIndex + 1 ) % ui8Size; // zerodiv error
if the class is instantiated with zero, but stop during compliation.
I found the main issue was due to template specialization. I included a full code example below.
Cppcheck doesn't take into account that template<typename T,="" UINT8="" ui8Size=""> inline T Filter<T, ui8Size="">::filterValue( const T tValue )
is never called with 0 because of a specialization above.
Hi everyone
I have the following (nonsensical) minimal example code which gives me two cppcheck errors:
Error for static_assert
2 1.76.1 duplicateExpression style Same expression on both sides of '<'. Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
Error for zerodiv
2 1.76.1 zerodiv error Division by zero. Division by zero.
Does anyone know if this is a false positive or if not how I can change my code to not get errors.
Last edit: Nikolai 2016-12-22
It seems to me that you instantiate the template method with ui8Size=0 somewhere. Then ui8Size is replaced with 0.. so "0 < ui8Size" becomes "0 < 0" and "% ui8Size" becomes "% 0".
So the warnings are technically correct.
I don't want that we report duplicateExpression for this code. This is a false positive. I believe there are tickets about this already.
About the zero division. If you instantiate the method with 0 then you get "% 0" that means division by zero. I don't see why that would be a false positive. So I believe it's only a false positive if you don't instantiate with 0.
Dear Daniel,
thank you for the quick response. I was on holidays and didn't have access to the codebase.
The point with static_assert is, it should never reach the line,
ui8WindowIndex = ( ui8WindowIndex + 1 ) % ui8Size; // zerodiv error
if the class is instantiated with zero, but stop during compliation.
I found the main issue was due to template specialization. I included a full code example below.
Cppcheck doesn't take into account that
template<typename T,="" UINT8="" ui8Size="">
inline T Filter<T, ui8Size="">::filterValue( const T tValue )
is never called with 0 because of a specialization above.
Last edit: Nikolai 2017-01-05