--suppress on line 0#1354
Conversation
added the ability to use suppress on line 0, since cppcheck can yield syntax error on line 0.
|
Hello, I discussed quite extensively with PKEuS about this issue. it is possible for cppcheck to suppress syntax errors, you can run it with --suppress=syntaxError, however cppcheck can also give you an error that several people have encountered which is a syntaxError on line 0, and this cannot be suppressed because line 0 was not recognized by cppcheck as a valid line. |
|
|
||
| if (suppression.lineNumber > 0) { | ||
| if (suppression.lineNumber >= Suppressions::Suppression::NO_LINE) { |
There was a problem hiding this comment.
I guess the >= should be >
There was a problem hiding this comment.
yes, you are correct, good catch!
danmar
left a comment
There was a problem hiding this comment.
I think it can be simplified
| e.errorMessage, | ||
| e.id, | ||
| false); | ||
| cppCheck.reportErr(errmsg); |
There was a problem hiding this comment.
I am not sure if you really need to test this with the entire CppCheck and Tokenizer.
Can't you just write something like:
void suppressionsLine0() {
Suppressions suppressions;
suppressions.addSuppressionLine("syntaxError:*:0");
ASSERT_EQUALS(true, suppressions.isSuppressed(errorMessage("syntaxError", "test.cpp", 0)));
}
There was a problem hiding this comment.
ah perhaps, this is my first contribution to cppcheck so I'm not very familiar with it yet :D perhaps your code works! I'll check it in a week after my holidays!
There was a problem hiding this comment.
this is my first contribution to cppcheck so I'm not very familiar with it yet
Yes of course! I totally understand this. Sorry, I meant no disrespect at all.
There was a problem hiding this comment.
I know you didn't ;) now that I see your proposal more clearly, it makes a lot of sense 👍
| suppressions.clear(); | ||
| suppressions.emplace_back("abc", "a.c", 10U); | ||
| suppressions.emplace_back("unmatchedSuppression", "*", 0U); | ||
| suppressions.emplace_back("unmatchedSuppression", "*", /*Suppressions::Suppression::NO_LINE*/-1); //TODO find out why clang can't link with Suppressions::Suppression::NO_LINE |
There was a problem hiding this comment.
The problem you had was a linker error because there is no definition for Suppressions::Suppression::NO_LINE.
I would guess that if you replace the variable with such constant it will work:
enum {NO_LINE=-1};
Another solution is to add a variable definition.. but that is unfortunate.
There was a problem hiding this comment.
well the constant is defined in suppression.h which is included in testerrorlogger.cpp. adding a new constant with the same value just for the purpose of making clang happy is a bit over the top in my opinion, other linkers (VC and GCC) didn't complain :/
There was a problem hiding this comment.
I want that you replace the variable declaration in suppression.h
This line in suppressions.h:
static const int NO_LINE = -1;
Write this instead:
enum { NO_LINE = -1 };
other linkers (VC and GCC) didn't complain
In my humble opinion that is strange. Maybe I am wrong, but the code is not valid as far as I see.
There was a problem hiding this comment.
As I read it on this page:
https://en.cppreference.com/w/cpp/language/static
the code is not valid. you need to define Suppressions::Suppression::NO_LINE also.
| * and if it's possible at all */ | ||
| bool isUnusedFunctionCheckEnabled() const; | ||
|
|
||
| /** |
There was a problem hiding this comment.
If the test is rewritten as I suggest I assume you can revert these changes.
added the ability to use suppress on line 0, since cppcheck can yield syntax error on line 0.