Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion man/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,21 @@ Or at the same line as the code:
arr[10] = 0; // cppcheck-suppress arrayIndexOutOfBounds
}

In this example there are 2 lines with code and 1 suppression comment. The suppression comment only applies to 1 line: `a = b + c;`.
The suppression comment and the line of code may be separated by additional comments or empty lines:

void f() {
char arr[5];

// cppcheck-suppress arrayIndexOutOfBounds

arr[10] = 0;

// cppcheck-suppress arrayIndexOutOfBounds
// Set the tenth element of arr to zero
arr[10] = 0;
}

In the example below there are 2 lines with code and 1 suppression comment. The suppression comment only applies to 1 line: `a = b + c;`.

void f() {
a = b + c; // cppcheck-suppress abc
Expand Down
33 changes: 33 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class TestPreprocessor : public TestFixture {

// inline suppression, missingInclude/missingIncludeSystem
TEST_CASE(inline_suppressions);
TEST_CASE(inline_suppressions_not_next_line);

// remark comment
TEST_CASE(remarkComment1);
Expand Down Expand Up @@ -2030,6 +2031,38 @@ class TestPreprocessor : public TestFixture {
ignore_errout(); // we are not interested in the output
}

void inline_suppressions_not_next_line() {
const auto settings = dinit(Settings,
$.inlineSuppressions = true,
$.checks.enable (Checks::missingInclude));

const char code[] = "// cppcheck-suppress missingInclude\n"
"// some other comment\n"
"#include \"missing.h\"\n"
"// cppcheck-suppress missingIncludeSystem\n"
"\n" // Empty line
"#include <missing2.h>\n";
SuppressionList inlineSuppr;
(void)getcodeforcfg(settings, *this, code, "", "test.c", &inlineSuppr);

auto suppressions = inlineSuppr.getSuppressions();
ASSERT_EQUALS(2, suppressions.size());

auto suppr = suppressions.front();
suppressions.pop_front();
ASSERT_EQUALS("missingInclude", suppr.errorId);
ASSERT_EQUALS("test.c", suppr.fileName);
ASSERT_EQUALS(3, suppr.lineNumber);

suppr = suppressions.front();
suppressions.pop_front();
ASSERT_EQUALS("missingIncludeSystem", suppr.errorId);
ASSERT_EQUALS("test.c", suppr.fileName);
ASSERT_EQUALS(6, suppr.lineNumber);

ignore_errout();
}

void remarkComment1() {
const char code[] = "// REMARK: assignment with 1\n"
"x=1;\n";
Expand Down
Loading