Skip to content

Unused exclude - #8906

Draft
danmar wants to merge 3 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:unused-exclude
Draft

danmar wants to merge 3 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:unused-exclude

Conversation

@danmar

@danmar danmar commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Overlapping patterns are misreported, some build paths no longer compile, and GUI project analysis omits validation.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity · 2 Low severity

Open (5)
What changed in this PR

Adds detection and reporting for unused ignore/exclude patterns across CLI and GUI analysis flows.

Changes:

  • Tracks matched patterns in PathMatch.
  • Reports unused exclusions during CLI and GUI analysis.
  • Adds coverage for matching and reporting behavior.
File Description
lib/​pathmatch.h Adds match tracking API and state.
lib/​pathmatch.cpp Records matched patterns.
lib/​importproject.h Returns unmatched project exclusions.
lib/​importproject.cpp Collects unmatched project exclusions.
cli/​filelister.h Makes matcher parameters mutable.
cli/​filelister.cpp Propagates mutable matchers.
cli/​cmdlineparser.cpp Rejects unused exclusions.
gui/​filelist.h Exposes unmatched exclusions.
gui/​filelist.cpp Computes unmatched exclusions.
gui/​mainwindow.cpp Displays unused-exclusion warnings.
gui/​test/​filelist/​testfilelist.h Declares new GUI tests.
gui/​test/​filelist/​testfilelist.cpp Tests unmatched GUI exclusions.
test/​testpathmatch.cpp Tests pattern tracking.
test/​testfilelister.cpp Updates matcher usage.
test/​testcmdlineparser.cpp Tests CLI validation.
test/​helpers.cpp Updates helper matcher usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cli/filelister.h
* @return On success, an empty string is returned. On error, a error message is returned.
*/
static std::string addFiles(std::list<FileWithDetails> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored, bool debug = false);
static std::string addFiles(std::list<FileWithDetails> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, PathMatch& ignored, bool debug = false);
Comment thread lib/importproject.cpp
else
++it;
}
return matcher.unmatched();
Comment thread lib/pathmatch.cpp
Comment on lines 36 to +40
return std::any_of(mPatterns.cbegin(), mPatterns.cend(), [&] (const std::string &pattern) {
return match(pattern, path, mBasepath, mode, mSyntax);
const bool res = match(pattern, path, mBasepath, mode, mSyntax);
if (res)
mMatchedPatterns.insert(pattern);
return res;
Comment thread cli/cmdlineparser.cpp

const auto& unmatched = matcher.unmatched();
if (!unmatched.empty()) {
mLogger.printError("unused ignore/exclude path '" + unmatched.front() + "' to hide warnings in certain files use suppressions instead.");
Comment thread gui/mainwindow.cpp
if (!unmatchedExcludePaths.isEmpty()) {
QMessageBox msg(QMessageBox::Warning,
"Cppcheck",
tr("Unused exclude paths:\n%1\nto hide warnings in certain files use suppressions instead").arg(unmatchedExcludePaths.join("\n")),
Copilot AI balanced review requested due to automatic review settings September 30, 2026 20:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Windows compilation is broken, and several paths can incorrectly or inconsistently report unused exclusions.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity · 2 Low severity

Open (5)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate project excludes against the complete file set

gui/​mainwindow.cpp:694

This check evaluates project-wide excludes only against the current files argument. checkProject() passes recheckFiles here when rechecking a modified subset (mainwindow.cpp:1986-1995), so any valid project exclude that only matches a file outside that subset is reported as unused and the recheck is aborted. Restrict this validation to a full analysis, or validate against the complete project input set rather than the recheck subset.

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.

3 participants