Repository navigation
Conversation
582af1e to
7f4334b
Compare
|
@claude review |
| // paths inside a matched directory are not traversed, so a pattern that is | ||
| // covered by a matched pattern is considered used | ||
| const Filemode mode = !s.empty() && PathIterator::issep(s.back(), mSyntax) ? Filemode::directory : Filemode::regular; | ||
| return std::none_of(mMatchedPatterns.cbegin(), mMatchedPatterns.cend(), [&](const std::string& matched) { |
There was a problem hiding this comment.
False negative: this "covered by a matched pattern" check runs against every matched pattern, but the reasoning only holds for patterns that matched a directory. Only directory matches stop the traversal. A file pattern never hides anything.
Examples where a stale pattern goes unreported:
-ifoo.cpp -inonexistent/foo.cpp:foo.cppmatcheslib/foo.cpp, andmatch("foo.cpp", "nonexistent/foo.cpp")is true, so the second pattern counts as used.-i*_test.cpp -imissing_test.cpp: the glob matches some file, somissing_test.cppis never reported.
Suggestion: keep track of which patterns matched with Filemode::directory, and only use those for this check.
|
|
||
| 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."); |
There was a problem hiding this comment.
A couple of points about making this a hard error:
- Only
unmatched.front()is reported. If a user has several stale-ipaths, they have to fix one and re-run for each. Listing all of them would be easier to use (same for the project branch below). -ifoo.hnow always fails, because headers are never passed tomatch(). The user first sees the existing "filename exclusion does not apply to header files" info message and then this error. It may be worth making the two messages consistent.- Builds that share one ignore list across different path arguments will now fail. So will builds that ignore generated directories that don't exist yet, e.g.
-ibuild/on a fresh checkout. Is a hard error (rather than a warning) intended here? If so, the release note should call it out as a breaking change.
|
Overall the approach looks good:
🤖 Generated with Claude Code |
141c611 to
5e52f82
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
New false positive in PathMatch::unmatched(). An exclude pattern that matches files only inside a directory that another pattern already excludes is reported as unused, and the run stops with exit code 1. The "covered" check only compares the two pattern strings with each other (match("src/sub/", "b.c")). It never asks whether the second pattern would match something inside the skipped directory. So -ithird_party/ -i*.pb.cc . fails when all .pb.cc files are under third_party/. Ignore lists like this are common, and they worked before this PR. In my tests this was the only new problem.
Several earlier points are still in the code:
MainWindow::doAnalyzeProjectstill discards the result ofignorePaths(C2/C18).- The covered check still hides stale file/glob patterns (C11/C16).
- The GUI message is still a run-on sentence (C6).
- Only the first unused path is reported (C17).
Comments
18 comments, 6 open, 1 new
@danmar, please fix, resolve or reply to the open and new comments: #9, #12, #13, #15, #16, #17, #18.
For #9, #12, #16 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
Builds
make -j8 cppcheck testrunnerinpr/built without errors.- I also built the GUI and its tests with CMake.
Unit and GUI tests
./testrunner TestPathMatch TestCmdlineParser TestFileLister TestImportProject: 466 tests, 0 failed.- GUI ctest (
test-filelistand the others): 5/5 passed.
Python tests in test/cli
- 585 passed and 16 failed.
- 12 of the failures are rule tests, because this build has no rules support ("Option --rule ...").
- The other 4 are
test_redundant_file_reads, which fails withFileNotFoundError, most likely a tool missing in the container. - I don't think any of these failures are related to the PR, but I did not run them against
base/.
Manual CLI tests (in /work/scratch/t1)
- These pass:
-isrc/sub/ src,-isub src,-i./src/sub/ src, absolute-i,-isrc/sub/ src/sub/b.c src/a.c, and-isrc/sub/ -i**/sub/ src.
Reproducer for the false positive
mkdir -p src/sub third_party/proto
echo "int a;" > src/a.c; echo "int b;" > src/sub/b.c; echo "int p;" > third_party/proto/x.pb.cc
$ cppcheck -q -isrc/sub/ -ib.c src
cppcheck: error: unused ignore/exclude path 'b.c'. To hide warnings in certain files use suppressions instead.
rc=1
$ cppcheck -q -isrc/sub/ -isub/b.c src
cppcheck: error: unused ignore/exclude path 'sub/b.c'. To hide warnings in certain files use suppressions instead.
rc=1
$ cppcheck -q -ithird_party/ -i*.pb.cc .
cppcheck: error: unused ignore/exclude path '*.pb.cc'. To hide warnings in certain files use suppressions instead.
rc=1
In each case the reported pattern does match an existing file (src/sub/b.c, third_party/proto/x.pb.cc). It is reported only because the directory is never traversed. Without this PR these command lines run normally.
Automated review of 0d886c7 by Claude. The pull request was built and tested locally.
| // paths inside a matched directory are not traversed, so a pattern that is | ||
| // covered by a matched pattern is considered used | ||
| const Filemode mode = !s.empty() && PathIterator::issep(s.back(), mSyntax) ? Filemode::directory : Filemode::regular; | ||
| return std::none_of(mMatchedPatterns.cbegin(), mMatchedPatterns.cend(), [&](const std::string& matched) { |
There was a problem hiding this comment.
AI review
The covered check only tests whether a matched pattern matches the text of the unmatched pattern. When a directory is excluded, files below it are never passed to match(). So a pattern that would only match files in there is reported as unused even though it does match existing files, unless its text happens to start with the directory's path. Examples that now fail with exit code 1:
$ cppcheck -isrc/sub/ -ib.c src # src/sub/b.c exists
cppcheck: error: unused ignore/exclude path 'b.c'. ...
$ cppcheck -isrc/sub/ -isub/b.c src
cppcheck: error: unused ignore/exclude path 'sub/b.c'. ...
$ cppcheck -ithird_party/ -i*.pb.cc . # all .pb.cc are below third_party/
cppcheck: error: unused ignore/exclude path '*.pb.cc'. ...
Ignore lists like -ithird_party/ -i*.pb.cc are common, and they worked before this PR. A comparison of pattern strings can't decide whether one pattern is "covered" by another. Two possible fixes:
- Keep walking the excluded directories (or at least record the paths below them) when you collect which patterns are used.
- Report an unmatched pattern only when it could not match anything in an excluded directory.
|
Test results for commit 0d886c7 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8906/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
Add the scenario "Unused exclude paths are reported" with the test project unused-exclude: one exclude path that matches a file and one that matches nothing. Only the unused path is reported. Regenerate the script of "Other Help menu entries" against a build that has online-help.qhc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2208e48 to
fe65619
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The GUI and the CLI no longer agree on what counts as a used exclude. FileList::applyExcludeList() only passes the source files that were collected to PathMatch::match(). Directories are never passed, and neither are headers or other non-source files. So a project exclude for an existing directory with no .c/.cpp files (for example include/ with only headers, a header-only library, or a build/ directory) is reported as unused, and the GUI aborts the analysis. The CLI accepts the same exclude, because the file lister matches directories too. I reproduced this.
The CLI fix for the C21 false positive works. -isrc/sub/ -ib.c src and -ithird_party/ -i*.pb.cc . now pass, and the earlier false negatives from the "covered" check (C11/C16) are gone. I found no other new problems in the CLI paths I tested (plain paths, .cppcheck projects, compile_commands.json, vcxproj/sln with --file-filter).
Comments
19 comments, 4 open, 1 new
@danmar, please fix, resolve or reply to the open and new comments: #13, #15, #16, #17, #19.
For #16 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
Build: make -j8 cppcheck testrunner built cleanly in pr/ and base/. I did not build the full GUI with CMake. To test gui/filelist.cpp I compiled it against Qt6Core in a small driver program.
Unit tests: ./testrunner TestPathMatch TestCmdlineParser TestFileLister TestImportProject: 471 tests, 0 failed.
Python tests in test/cli: 585 passed, 16 failed. All 16 failures are unrelated to this PR: 12 are rule tests (this build has no rules support), and 4 are test_redundant_file_reads, the same failures as in the previous review.
Manual CLI tests (in scratch/t, with src/a.c, src/sub/b.c and third_party/proto/x.pb.cc):
These now return rc=0:
-isrc/sub/ -ib.c src-isrc/sub/ -isub/b.c src-ithird_party/ -i*.pb.cc .-isrc/build/ src, where the directory has only a.ofile-isrc/empty/ src
These are rejected:
-imissing/-ia.c -inonexistent/a.c src, so the earlier false negative is fixed
Other projects:
.cppcheckproject with excludes: works, also when run from the parent directory.- compile_commands.json with
-isrc/sub/,-ib.c,-isub/and--file-filter: same results as base.-imissing/is now an error. helloworld.vcxproj/.slnwith--file-filter: same output as base.
GUI problem (reproduced):
proj/src/a.c // int a;
proj/include/h.h // int h;
Driver (scratch/gq/main.cpp):
QDir::setCurrent(argv[1]);
FileList l; l.addExcludeList(QStringList() << "include/");
l.addPathList(QStringList() << QString(argv[1]));
std::cout << "files=" << l.getFileList().size() << "\n";
for (const QString& s : l.getUnmatchedExcludes()) std::cout << "unmatched: " << s.toStdString() << "\n";$ g++ -std=c++17 -fPIC -I pr/gui -I pr/lib -I$Q -I$Q/QtCore main.cpp pr/gui/filelist.cpp pr/lib/{pathmatch,path,utils}.o pr/externals/simplecpp/simplecpp.o -lQt6Core -o gq && ./gq $PWD/proj
files=1
unmatched: include/
$ cd proj && cppcheck -q -iinclude/ . ; echo $?
0
With this exclude in a project file, the GUI would show the "Unused exclude paths" box and not analyze anything. The CLI accepts the same exclude.
Automated review of fe65619 by Claude. The pull request was built and tested locally.
| paths << canonical; | ||
| } | ||
|
|
||
| for (const std::string& excludePath: pathMatch.unmatched()) { |
There was a problem hiding this comment.
AI review
pathMatch.match() is only called for the source files in mFileList. addDirectory() drops headers and other non-source files, and directories are never matched. So an exclude for an existing directory that has no .c/.cpp files is reported as unused, and doAnalyzeFiles() aborts the analysis. Typical cases are include/, a header-only third-party directory, or build/. The CLI accepts the same exclude, because FileLister calls match(..., Filemode::directory) for every directory it walks.
Reproduced with proj/src/a.c and proj/include/h.h, exclude include/: getUnmatchedExcludes() returns include/, while cppcheck -iinclude/ . returns 0.
Possible fix: also match the directories that addDirectory() walks (with Filemode::directory) when you collect the used patterns, the same way the CLI does.
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems in this PR. The head is still fe65619, and the last automated review (C23/C24) already covered that commit. Several earlier points are still open:
- GUI directory excludes (C24): an exclude for an existing directory that has no source files (
include/,build/) is reported as unused, and the analysis stops. The CLI accepts the same exclude. - GUI imported projects (C2/C18):
MainWindow::doAnalyzeProjectstill throws away the result ofignorePaths(), so these projects never report unused excludes. - First path only (C17): the CLI reports only the first unused path.
- Hard error (C13/C17): an unused exclude is still a hard error, which breaks some existing command lines.
- Tests (C18): no CLI or Python tests were added for
.cppcheckexcludedPathsor for--file-filterwith vcxproj/sln.
Comments
18 comments, 5 open, 0 new
@danmar, please fix, resolve or reply to the open and new comments: #12, #14, #15, #16, #18.
For #15 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
Build: make -j8 cppcheck testrunner in pr/ built without errors. I did not build the GUI.
Unit tests: ./testrunner TestPathMatch TestCmdlineParser TestFileLister TestImportProject finished with 0 failures.
Manual CLI tests (src/a.c, src/sub/b.c, src/notes.txt):
-isrc/sub/ -isub/ src,-i./src/sub srcand-isrc/sub/b.c --file-filter=src/a.c srcreturn rc=0.-isrc/sub/ -ifoo.c -ibar.c srcgives rc=1, but the message names onlyfoo.c. This is the C17 point.-isrc/notes.txt srcgives rc=1 with "unused ignore/exclude path": an exclude for an existing non-source file counts as unused. This is the same kind of case as the header excludes in C14, which the author accepted, so I do not report it as a new problem.
I found no new problems.
Automated review of fe65619 by Claude. The pull request was built and tested locally.
|
Test results for commit fe65619 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8906/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
No description provided.