From 59a60fa33e7c705817204b29fb556932ce204a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 2 Feb 2026 16:38:50 +0100 Subject: [PATCH 1/2] Add test --- test/testpreprocessor.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index f0885308c73..f38b61b8a66 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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); @@ -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 \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"; From ea34a4a65071416039bff2c28c6a99088c0fa196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 2 Feb 2026 16:45:00 +0100 Subject: [PATCH 2/2] Update manual --- man/manual.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/man/manual.md b/man/manual.md index d8da119f388..1a4e4002f10 100644 --- a/man/manual.md +++ b/man/manual.md @@ -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