Skip to content

Commit

Permalink
fixed #12424 - CppCheck: provide a preprocessor object with --clang
Browse files Browse the repository at this point in the history
… (fixes assert)
  • Loading branch information
firewave committed Feb 28, 2024
1 parent 4114205 commit c1724ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymbolDatabase&>(*tokenizer.getSymbolDatabase()),
Expand Down
13 changes: 12 additions & 1 deletion test/cli/clang-import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 == ''

0 comments on commit c1724ca

Please sign in to comment.