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:
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.
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:
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.
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