Skip to content

Fix #15303 Fix symbolName suppressions not matching results loaded from the build dir - #9101

Open
weggert2 wants to merge 1 commit into
cppcheck-opensource:mainfrom
weggert2:symbolname-xml-cache
Open

weggert2 wants to merge 1 commit into
cppcheck-opensource:mainfrom
weggert2:symbolname-xml-cache

Conversation

@weggert2

@weggert2 weggert2 commented Dec 1, 2026

Copy link
Copy Markdown

Problem

With --cppcheck-build-dir, a finding suppressed through an XML <symbolName> suppression is suppressed on the first run, but reported again on every rerun of an unchanged file (i.e. whenever results are loaded from the build dir).

I don't have a Trac account, so there is no ticket for this yet. Happy to have one filed and linked.

Reproduction

test.cpp:

struct Base {
    void init() {}
};
struct Derived : Base {
    void init() {}
};

suppr.xml:

<?xml version="1.0"?>
<suppressions>
  <suppress>
    <id>duplInheritedMember</id>
    <symbolName>init</symbolName>
  </suppress>
</suppressions>
mkdir b1
cppcheck -q -j2 --enable=warning --suppress-xml=suppr.xml --cppcheck-build-dir=b1 test.cpp   # no output
cppcheck -q -j2 --enable=warning --suppress-xml=suppr.xml --cppcheck-build-dir=b1 test.cpp   # duplInheritedMember reported

Reproduces with 2.19.0 and current main. On main it also happens with -j1.

Cause

ErrorMessage keeps its symbol names newline-separated (setmsg() keeps the \n from each $symbol: line, giving e.g. "Derived\ninit\nBase\n"), and toXML() writes one <symbol> element per name, so the cached .a1 file is correct. However, the ErrorMessage(const tinyxml2::XMLElement*) constructor used when loading those results appends the names without the separator (mSymbolNames += e->GetText();), producing "DerivedinitBase". SuppressionList::Suppression::isMatch() splits symbolNames on \n, so the suppression no longer matches.

Fix

Append the \n separator for each <symbol> element in the XML constructor.

Tests

  • TestErrorLogger::FromXmlSymbolNames: round trip through toXML() and the XML constructor keeps symbolNames() intact (fails without the fix: sym1sym2 instead of sym1\nsym2\n).
  • test/cli/other_test.py: test_suppress_xml_symbolname*, running with and without the build dir, -j1 and -j2, twice each. The two cached variants fail without the fix.

Ran testrunner (all pass) plus test/cli/other_test.py, inline-suppress_test.py and whole-program_test.py locally. The only failures were the --rule tests, because my local build has no rules support.

…d dir

ErrorMessage stores symbol names newline-separated. toXML() writes one
<symbol> element per name, but the XML constructor appended them without
the separator, so results reloaded from --cppcheck-build-dir had a single
concatenated symbol name and symbolName suppressions no longer matched.
@dmcppcheck

Copy link
Copy Markdown
Contributor

There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated.

@weggert2

weggert2 commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

I don't have a Trac account, can you please help me create the ticket? EDIT: I also sent you a Trac message to make an account

@weggert2 weggert2 changed the title Fix symbolName suppressions not matching results loaded from the build dir #15303 Fix symbolName suppressions not matching results loaded from the build dir Dec 2, 2026
@weggert2 weggert2 changed the title #15303 Fix symbolName suppressions not matching results loaded from the build dir Fix #15303 Fix symbolName suppressions not matching results loaded from the build dir Dec 2, 2026
@weggert2

weggert2 commented Dec 2, 2026

Copy link
Copy Markdown
Author

Trac account created, ticket made, PR title updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants