Skip to content

Fix #15221 (Deprecate the clang import) - #9031

Open
danmar wants to merge 5 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15221
Open

danmar wants to merge 5 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15221

Conversation

@danmar

@danmar danmar commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck

Copy link
Copy Markdown
Contributor

Tests may be missing

@ludviggunne

Copy link
Copy Markdown
Collaborator

If it's mentioned in the manual maybe we should say that it's deprecated there too?

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review

The new deprecation message goes through the normal error path (mErrorLogger.reportErr). Because of that it counts as a finding: --clang --error-exitcode=1 now exits with 1 on code that has no issues. That would break CI jobs that use --clang as soon as they upgrade. The message is also repeated for every checked file, and for empty files it prints an empty code snippet. A deprecation warning from the command line parser, printed once per run and not counted as a finding, would avoid both problems. The releasenotes change also rewrites the unrelated PCRE2 entry and adds a duplicate "Rules:" item about PCRE2 under "Options". Apart from that I found no problems.

Comments

# Comment By Where Status
1 Tests may be missing @dmcppcheck general ✅ Fixed
2 Manual should say that the clang import is deprecated @ludviggunne general ✅ Fixed
3 Deprecation notice counts as a finding: --error-exitcode fails on clean code AI review lib/cppcheck.cpp:691 🆕 New
4 Unrelated PCRE2 releasenotes rewrite and duplicate entry AI review releasenotes.txt:5 🆕 New

@danmar, please fix, resolve or reply to the open and new comments: #3, #4.

Testing

I built cppcheck and testrunner in pr/ with no errors. I ran python3 -m pytest clang-import_test.py in test/cli (clang is installed here): 38 passed.

Manual tests with a.c containing int f(int x){return x;}, b.c containing a function, and an empty file empty.c:

$ cppcheck --clang --error-exitcode=1 -q a.c; echo ec=$?
a.c:1:1: information: clang import is deprecated, it will be removed in 2.27 [clangimport]
int f(int x){return x;}
^
ec=1
$ cppcheck --clang --error-exitcode=1 -q --suppress=clangimport a.c; echo ec=$?
ec=0

Before the PR, --error-exitcode=1 gave exit code 0 on this clean file.

$ cppcheck --clang -q a.c b.c empty.c
a.c:1:1: information: clang import is deprecated, ... [clangimport]
int f(int x){return x;}
^
b.c:1:1: information: clang import is deprecated, ... [clangimport]

^
empty.c:1:1: information: clang import is deprecated, ... [clangimport]

^
  • The message is printed once per file, also with -j2.
  • It is also written to --xml output as an <error id="clangimport">.
  • It is printed again on every run with --cppcheck-build-dir.
  • clangimport is not listed in --errorlist.

I did not test the GUI because it can't be built here.


Automated review of 97a960c by Claude. The pull request was built and tested locally.

Comment thread lib/cppcheck.cpp
ErrorMessage errmsg;
errmsg.callStack.emplace_back(file.spath(), 1, 1);
errmsg.setmsg("clang import is deprecated, it will be removed in 2.27");
errmsg.severity = Severity::information;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review

The notice goes through mErrorLogger.reportErr, so it is handled like any other finding. cppcheck --clang --error-exitcode=1 -q a.c on a file without any issues now returns 1 (it returned 0 before). Every CI job that uses --clang with --error-exitcode will start failing.

The notice is also emitted once per checked file (and per run with --cppcheck-build-dir). For empty files it comes with an empty code snippet, and it shows up in xml/sarif results as an <error id="clangimport">.

A one-time warning printed in CmdLineParser when --clang (or a project with <parser>clang</parser>) is used would avoid all of this, e.g. mLogger.printMessage("'--clang' is deprecated and will be removed in Cppcheck 2.27."). If you keep it as an ErrorMessage, it should at least not affect the exit code, and the id should appear in --errorlist.

Comment thread releasenotes.txt
Release Notes for Cppcheck 2.23

Options:
- Rules: The PCRE library that we used is end-of-life. We have switched to PCRE2 instead. Existing rule files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review

This adds a second PCRE2 entry under "Options", which duplicates the one under "Infrastructure & dependencies". It also changes that existing entry from "Existing rule patterns and rule files work unchanged" to "will hopefully work". Neither change is related to the clang import deprecation, so it should probably go into a separate PR or be dropped.

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