Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,13 +1793,8 @@ void CmdLineParser::printHelp() const
" incomplete info.\n"
" --checkers-report=<file>\n"
" Write a report of all the active checkers to the given file.\n"
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
" parser. Takes the executable as optional parameter and\n"
" defaults to `clang`. Cppcheck will run the given Clang\n"
" executable, import the Clang AST and convert it into\n"
" Cppcheck data. After that the normal Cppcheck analysis is\n"
" used. You must have the executable in PATH if no path is\n"
" given.\n"
" --clang=<path> Deprecated: Use Clang parser instead of the builtin Cppcheck\n"
" parser. This option will be removed in Cppcheck 2.27.\n"
" --config-exclude=<dir>\n"
" Path (prefix) to be excluded from configuration\n"
" checking. Preprocessor configurations defined in\n"
Expand Down
5 changes: 4 additions & 1 deletion gui/projectfile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,11 @@
</item>
<item>
<widget class="QRadioButton" name="mBtnClangParser">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Clang (experimental)</string>
<string>Clang (this feature is deprecated; this option will be removed in 2.27)</string>
</property>
</widget>
</item>
Expand Down
10 changes: 10 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,16 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
{
// TODO: clear exitcode

// #15221 - clangimport is deprecated and will be removed
{
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;
errmsg.id = "clangimport";
mErrorLogger.reportErr(errmsg);
}

if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
mUnusedFunctionsCheck.reset(new CheckUnusedFunctions());

Expand Down
12 changes: 0 additions & 12 deletions man/manual-premium.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ Typically a `compile_commands.json` contains absolute paths. However no matter i
- a file with relative path `test1.cpp` can be checked.
- a file with relative path `test/somefile.cpp` is not checked

### Clang parser (experimental)

By default Cppcheck uses an internal C/C++ parser. However there is an experimental option to use the Clang parser instead.

Install `clang`. Then use Cppcheck option `--clang`.

Cppcheck executes clang with the -ast-dump option, imports the output, converts it to Cppcheck's internal format, and then
performs standard analysis.

You can also pass a custom Clang executable to the option by using for example `--clang=clang-10`. You can also pass it
with a path. On Windows it will append the `.exe` extension unless you use a path.

## Severities

The possible severities for messages are:
Expand Down
12 changes: 0 additions & 12 deletions man/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ Typically a `compile_commands.json` contains absolute paths. However no matter i
- a file with relative path `test1.cpp` can be checked.
- a file with relative path `test/somefile.cpp` is not checked

### Clang parser (experimental)

By default Cppcheck uses an internal C/C++ parser. However there is an experimental option to use the Clang parser instead.

Install `clang`. Then use Cppcheck option `--clang`.

Cppcheck executes clang with the -ast-dump option, imports the output, converts it to Cppcheck's internal format, and then
performs standard analysis.

You can also pass a custom Clang executable to the option by using for example `--clang=clang-10`. You can also pass it
with a path. On Windows it will append the `.exe` extension unless you use a path.

## Severities

The possible severities for messages are:
Expand Down
9 changes: 7 additions & 2 deletions releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

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
will hopefully work without changes.
- The --clang option has been deprecated, it will be removed in Cppcheck 2.27

Major bug fixes & crashes:
-

Expand All @@ -22,8 +27,8 @@ Import project:
Infrastructure & dependencies:
- Added arm64 platform files arm64-windows.xml, arm64-linux.xml and arm64-macos.xml (Apple Silicon).
These describe the default setup for that OS. The arm64-wchar_t2.xml and arm64-wchar_t4.xml files are kept.
- The rules feature (HAVE_RULES) now uses PCRE2 instead of the discontinued PCRE library. Existing rule patterns
and rule files work unchanged. On Windows the Visual Studio project now expects pcre2-8.lib and pcre2.h in externals.
- The rules feature (HAVE_RULES) now uses PCRE2 instead of the discontinued PCRE library. On Windows the
Visual Studio project now expects pcre2-8.lib and pcre2.h in externals.

Other:
-
28 changes: 22 additions & 6 deletions test/cli/clang-import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
import sys
import pytest
from testutils import cppcheck, assert_cppcheck
from testutils import cppcheck

try:
# TODO: handle exitcode?
Expand All @@ -20,6 +20,19 @@
pytest.skip(allow_module_level=True)


__DEPRECATION_MSG = 'information: clang import is deprecated, it will be removed in 2.27 [clangimport]'


# #15221 - clang import is deprecated; check the message and return the remaining stderr lines
def __check_deprecation(stderr, filename):
lines = stderr.splitlines()
assert len(lines) >= 3, lines
assert lines[0] == '{}:1:1: {}'.format(filename, __DEPRECATION_MSG), lines
# the message is followed by the code snippet and the caret
assert lines[2] == '^', lines
return lines[3:]


def __get_debug_section(title, stdout):
s = re.sub(r'0x[0-9a-fA-F]+', '0x12345678', stdout)
s = re.sub(r'nestedIn: Struct', 'nestedIn: Class', s)
Expand Down Expand Up @@ -125,7 +138,10 @@ def test_log(tmpdir):
'Checking {} ...'.format(test_file).replace('\\', '/'),
]

assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines)
exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stdout
assert stdout.splitlines() == out_lines
assert __check_deprecation(stderr, test_file) == []


def test_include(tmp_path):
Expand All @@ -151,7 +167,7 @@ def test_warning(tmpdir): # #12424
exitcode, stdout, stderr = cppcheck(['-q', '--enable=warning', '--clang', test_file])
assert exitcode == 0, stderr # do not assert
assert stdout == ''
assert stderr == ''
assert __check_deprecation(stderr, test_file) == []


def __test_cmd(tmp_path, file_name, extra_args, stdout_exp_1, content=''):
Expand All @@ -173,7 +189,7 @@ def __test_cmd(tmp_path, file_name, extra_args, stdout_exp_1, content=''):

exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
assert exitcode == 0, stderr if not stdout else stdout
assert stderr == ''
assert __check_deprecation(stderr, file_name) == []
assert stdout.splitlines() == [
'Checking {} ...'.format(file_name),
'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics {}{}'.format(stdout_exp_1, file_name)
Expand Down Expand Up @@ -279,7 +295,7 @@ def test_debug_clang_output(tmp_path):

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stderr if not stdout else stdout
assert stderr == ''
assert __check_deprecation(stderr, test_file) == []
assert stdout.startswith('TranslationUnitDecl'), stdout
assert stdout.find(str(test_file)) != -1, stdout

Expand Down Expand Up @@ -312,7 +328,7 @@ def test_debug_clang_output_failure_exitcode(tmp_path):

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stderr if not stdout else stdout
stderr_lines = stderr.splitlines()
stderr_lines = __check_deprecation(stderr, test_file)
assert len(stderr_lines) > 5, stderr_lines
assert (stderr_lines[0] ==
"Failed to execute 'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics -x c {} 2>&1' - (exitcode: 1 / output: {}:3:12: error: indirection requires pointer operand ('int' invalid)".format(test_file, test_file))
Expand Down
Loading