Hello guys, I've got, what I hope to be, a simple question.
I'm trying to suppress inline the "duplicateExpression" but I'm getting a "unmatched suppression" message.
I know the id is correct, because I configured cppcheck to print the id together with the error using the following template: --template "{file}:{line}: {severity} ({id}): {message}"
I'm using CppCheck version 1.75.
Am I missing something here? Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
C:\temp>cppcheck --enable=style --inline-suppr test.c
Checking test.c...
[test.c:5] -> [test.c:5]: (style) Same expression on both sides of '|'.
[test.c:7] -> [test.c:7]: (style) Same expression on both sides of '|'.
[test.c:8] -> [test.c:8]: (style) Same expression on both sides of '|'.
[test.c:10] -> [test.c:8]: (style) Same expression on both sides of '|'.
[test.c:10] -> [test.c:7]: (style) Same expression on both sides of '|'.
[test.c:11] -> [test.c:11]: (style) Same expression on both sides of '|'.
[test.c:12] -> [test.c:12]: (style) Same expression on both sides of '|'.
[test.c:13] -> [test.c:13]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:13]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:12]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:11]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:10]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:8]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:7]: (style) Same expression on both sides of '|'.
[test.c:16] -> [test.c:16]: (style) Same expression on both sides of '|'.
[test.c:17] -> [test.c:17]: (style) Same expression on both sides of '|'.
[test.c:18] -> [test.c:18]: (style) Same expression on both sides of '|'.
[test.c:19] -> [test.c:19]: (style) Same expression on both sides of '|'.
[test.c:20] -> [test.c:20]: (style) Same expression on both sides of '|'.
[test.c:4]: (style) Variable 'x' is assigned a value that is never used.
C:\temp>cppcheck --enable=style test.c
Checking test.c...
[test.c:5] -> [test.c:5]: (style) Same expression on both sides of '|'.
[test.c:7] -> [test.c:7]: (style) Same expression on both sides of '|'.
[test.c:8] -> [test.c:8]: (style) Same expression on both sides of '|'.
[test.c:10] -> [test.c:8]: (style) Same expression on both sides of '|'.
[test.c:10] -> [test.c:7]: (style) Same expression on both sides of '|'.
[test.c:11] -> [test.c:11]: (style) Same expression on both sides of '|'.
[test.c:12] -> [test.c:12]: (style) Same expression on both sides of '|'.
[test.c:13] -> [test.c:13]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:13]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:12]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:11]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:10]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:8]: (style) Same expression on both sides of '|'.
[test.c:15] -> [test.c:7]: (style) Same expression on both sides of '|'.
[test.c:16] -> [test.c:16]: (style) Same expression on both sides of '|'.
[test.c:17] -> [test.c:17]: (style) Same expression on both sides of '|'.
[test.c:18] -> [test.c:18]: (style) Same expression on both sides of '|'.
[test.c:19] -> [test.c:19]: (style) Same expression on both sides of '|'.
[test.c:20] -> [test.c:20]: (style) Same expression on both sides of '|'.
[test.c:4]: (style) Variable 'x' is assigned a value that is never used.
Any ideas how to solve this?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for the late reply. But Cppcheck should not warn about those because the expressions are not the same. Don't suppress when you see wrong warnings, tell us about it so we can fix Cppcheck.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using 1.86 and having trouble suppressing duplicat expressions. Here's my code the last line divides two results from getScale() and cppcheck obviously does not know that they are not the same so it generates an error. I tried to disable it with inline suppressions but in this case I still get the error
[layerdisplay/lib/LayerGLWidget.cpp:487] -> [layerdisplay/lib/LayerGLWidget.cpp:495]: (style) 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.
// cppcheck-suppress duplicateExpression
double old_scale = getScale(); // <<<< Line 487
const double zoom_step = 1.10;
float delta = -0.1 * mouseDelta.y();
setZoom((delta < 0) ? zoom() * zoom_step : zoom() / zoom_step);
// Adjust the pan on the widget so that the point under the mouse
// cursor stays in the same location when you zoom in.
// cppcheck-suppress duplicateExpression
double scale_ratio = getScale() / old_scale; // Line 495
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can not reproduce the duplicateExpression message with Cppcheck 1.86 or git HEAD using the code snippet. I guess Cppcheck only prints a message when the full code is analyzed?
Could you try to find a reduced code example where the issue still can be reproduced?
Or can you try if it still occurrs with git HEAD?
Regarding the supression:
Have you tried to move the inline suppression just before line 495? I guess this should be the line that really triggers the message. The marker for line 487 is just a note i think.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I already have a supression comment before 495, but found neither suppressed the message.
Using the code from HEAD I get a different message
[layerdisplay/lib/LayerGLWidget.cpp:487] -> [layerdisplay/lib/LayerGLWidget.cpp:495]: (style) Same expression on both sides of '/' because 'getScale()' and 'old_scale' represent the same value.
and the error is not suppressed.
I did find that the following will suppress the error
// cppcheck-suppress *
I tried to generate a standalone code snippet before posting but also could not reproduce it. I'll try again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and get this message
[/home/bobstaff/LayerGLWidget.cpp:71] -> [/home/bobstaff/LayerGLWidget.cpp:79]: (style) Same expression on both sides of '/' because 'getScale()' and 'old_scale' represent the same value.
Thanks, now i can reproduce the issue.
If i change the command line a little bit i get the following result for the file:
$ ./cppcheck --inline-suppr --library=qt --enable=all --platform=unix64 --template=gcc LayerGLWidget.cpp
Checking LayerGLWidget.cpp ...
LayerGLWidget.cpp:79:36: warning: Same expression on both sides of '/' because 'getScale()' and 'old_scale' represent the same value. [knownConditionTrueFalse]
double scale_ratio= getScale() / old_scale;
^
LayerGLWidget.cpp:71:31: note: 'old_scale' is assigned value 'getScale()' here.
double old_scale= getScale();
^
LayerGLWidget.cpp:79:36: note: Same expression on both sides of '/' because 'getScale()' and 'old_scale' represent the same value.
double scale_ratio= getScale() / old_scale;
^
LayerGLWidget.cpp:12:0: warning: The function'getZoom' is never used. [unusedFunction]
^
LayerGLWidget.cpp:63:0: warning: The function'mouseMoveEvent' is never used. [unusedFunction]
^
LayerGLWidget.cpp:16:0: warning: The function'range' is never used. [unusedFunction]
^
LayerGLWidget.cpp:71:0: warning: Unmatched suppression: duplicateExpression [unmatchedSuppression]
double old_scale= getScale();
^
LayerGLWidget.cpp:79:0: warning: Unmatched suppression: duplicateExpression [unmatchedSuppression]
double scale_ratio= getScale() / old_scale;
^
With the option --template=gcc the id of the message is shown (knownConditionTrueFalse in this case).
So the suppression in line 70 is useless and can be removed.
And the suppression in line 78 (or 77 after removing line 70) can be changed to // cppcheck-suppress knownConditionTrueFalse
Then i get:
$ ./cppcheck --inline-suppr --library=qt --enable=all --platform=unix64 --template=gcc LayerGLWidget.cpp
Checking LayerGLWidget.cpp ...
LayerGLWidget.cpp:12:0: warning: The function'getZoom' is never used. [unusedFunction]
^
LayerGLWidget.cpp:63:0: warning: The function'mouseMoveEvent' is never used. [unusedFunction]
^
LayerGLWidget.cpp:16:0: warning: The function'range' is never used. [unusedFunction]
^
While this does not fix the false positive it is at least possible to suppress it.
IMHO this is a false positive that should be fixed. I will create a ticket for that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello guys, I've got, what I hope to be, a simple question.
I'm trying to suppress inline the "duplicateExpression" but I'm getting a "unmatched suppression" message.
I know the id is correct, because I configured cppcheck to print the id together with the error using the following template: --template "{file}:{line}: {severity} ({id}): {message}"
I'm using CppCheck version 1.75.
Am I missing something here? Thanks.
it works for me:
Command line output:
does that work for you?
It doesn't.
I managed to create this simple test that demonstrates the problem:
Any ideas how to solve this?
Thanks.
Sorry for the late reply. But Cppcheck should not warn about those because the expressions are not the same. Don't suppress when you see wrong warnings, tell us about it so we can fix Cppcheck.
Anyway.. I guess you saw that this has been fixed. Latest Cppcheck does not warn.
I'm using 1.86 and having trouble suppressing duplicat expressions. Here's my code the last line divides two results from getScale() and cppcheck obviously does not know that they are not the same so it generates an error. I tried to disable it with inline suppressions but in this case I still get the error
[layerdisplay/lib/LayerGLWidget.cpp:487] -> [layerdisplay/lib/LayerGLWidget.cpp:495]: (style) 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.
I can not reproduce the
duplicateExpression
message with Cppcheck 1.86 or git HEAD using the code snippet. I guess Cppcheck only prints a message when the full code is analyzed?Could you try to find a reduced code example where the issue still can be reproduced?
Or can you try if it still occurrs with git HEAD?
Regarding the supression:
Have you tried to move the inline suppression just before line 495? I guess this should be the line that really triggers the message. The marker for line 487 is just a note i think.
I already have a supression comment before 495, but found neither suppressed the message.
Using the code from HEAD I get a different message
[layerdisplay/lib/LayerGLWidget.cpp:487] -> [layerdisplay/lib/LayerGLWidget.cpp:495]: (style) Same expression on both sides of '/' because 'getScale()' and 'old_scale' represent the same value.
and the error is not suppressed.
I did find that the following will suppress the error
// cppcheck-suppress *
I tried to generate a standalone code snippet before posting but also could not reproduce it. I'll try again.
Attached is a cut down version of my original code that still exhibits the problem (false positive and lack of suppression)
I'm invoking cppcheck (from HEAD) as follows
cppcheck
--inline-suppr
--library=qt.cfg
--enable=warning,style,performance,portability --platform=unix64 ~/LayerGLWidget.cpp
Last edit: Bob Stafford 2018-12-20
Thanks, now i can reproduce the issue.
If i change the command line a little bit i get the following result for the file:
With the option
--template=gcc
the id of the message is shown (knownConditionTrueFalse
in this case).So the suppression in line 70 is useless and can be removed.
And the suppression in line 78 (or 77 after removing line 70) can be changed to
// cppcheck-suppress knownConditionTrueFalse
Then i get:
While this does not fix the false positive it is at least possible to suppress it.
IMHO this is a false positive that should be fixed. I will create a ticket for that.
I have created a ticket:
https://trac.cppcheck.net/ticket/8916
Thanks