From c1724cad7c48c837088d8c2f480e5fa8b21198c2 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 28 Feb 2024 16:42:23 +0100 Subject: [PATCH] fixed #12424 - CppCheck: provide a preprocessor object with `--clang` (fixes assert) --- lib/cppcheck.cpp | 5 +++-- test/cli/clang-import_test.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9d214c9f146..1cc088120a7 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -499,9 +499,10 @@ unsigned int CppCheck::checkClang(const std::string &path) } try { - std::istringstream ast(output2); - Tokenizer tokenizer(mSettings, this); + Preprocessor preprocessor(mSettings, this); + Tokenizer tokenizer(mSettings, this, &preprocessor); tokenizer.list.appendFileIfNew(path); + std::istringstream ast(output2); clangimport::parseClangAstDump(tokenizer, ast); ValueFlow::setValues(tokenizer.list, const_cast(*tokenizer.getSymbolDatabase()), diff --git a/test/cli/clang-import_test.py b/test/cli/clang-import_test.py index fc98a4cf773..13be3cd05aa 100644 --- a/test/cli/clang-import_test.py +++ b/test/cli/clang-import_test.py @@ -139,4 +139,15 @@ def test_log(tmpdir): 'Checking {} ...'.format(test_file).replace('\\', '/'), ] - assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines) \ No newline at end of file + assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines) + + +def test_warning(tmpdir): # #12424 + test_file = os.path.join(tmpdir, 'test_2') + with open(test_file, 'wt') as f: + f.write('''void f() {}''') + + exitcode, stdout, stderr = cppcheck(['-q', '--enable=warning', '--clang', test_file]) + assert exitcode == 0, stderr # do not assert + assert stdout == '' + assert stderr == ''