If I run cppcheck 1.87 on the following code it warns me that the argument to setw is always 10. What is the intention of this? For now I have disabled this check because it doesn't seem to add any value.
[cppcheck_constargument.cpp:7]: (style) Argument 'columnWidths[0]' to function setw is always 10
[cppcheck_constargument.cpp:8]: (style) Argument 'columnWidths[1]' to function setw is always 10
[cppcheck_constargument.cpp:9]: (style) Argument 'columnWidths[0]' to function setw is always 10
[cppcheck_constargument.cpp:10]: (style) Argument 'columnWidths[1]' to function setw is always 10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
IMHO your example shows a false positive. Maybe the check can be improved to not warn in such cases.
Looking at the test cases for examples where Cppcheck should warn shows that there are cases where it makes sense to warn:
Here the argument was not meant to be constant. So it is a real error.
The corresponding ticket with the idea is here: https://trac.cppcheck.net/ticket/8830
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I run cppcheck 1.87 on the following code it warns me that the argument to setw is always 10. What is the intention of this? For now I have disabled this check because it doesn't seem to add any value.
IMHO your example shows a false positive. Maybe the check can be improved to not warn in such cases.
Looking at the test cases for examples where Cppcheck should warn shows that there are cases where it makes sense to warn:
Here the argument was not meant to be constant. So it is a real error.
The corresponding ticket with the idea is here:
https://trac.cppcheck.net/ticket/8830
I created a ticket: https://trac.cppcheck.net/ticket/8986
I agree.. it is a false positive.