Skip to content

Commit

Permalink
s [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Sep 24, 2024
1 parent cff0ea9 commit 7642b93
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,11 +1263,14 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
// --std
else if (std::strncmp(argv[i], "--std=", 6) == 0) {
const std::string std = argv[i] + 6;
// TODO: get rid of indirection
Standards tmp;
if (tmp.setC(std)) {
mSettings.standards.c = tmp.c;
mSettings.standards.stdValueC = tmp.stdValueC;
} else if (tmp.setCPP(std)) {
mSettings.standards.cpp = tmp.cpp;
mSettings.standards.stdValueCPP = tmp.stdValueCPP;
} else {
mLogger.printError("unknown --std value '" + std + "'");
return Result::Fail;
Expand Down
7 changes: 5 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,11 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
mErrorLogger.reportOut(std::string("Checking ") + file.spath() + " ...", Color::FgGreen);

// TODO: get language from FileWithDetails object
// TODO: this ignores the configured language
const bool isCpp = Path::identify(file.spath(), mSettings.cppHeaderProbe) == Standards::Language::CPP;
bool isCpp;
if (mSettings.enforcedLang != Standards::None)
isCpp = (mSettings.enforcedLang == Standards::CPP);
else
isCpp = Path::identify(file.spath(), mSettings.cppHeaderProbe) == Standards::Language::CPP;
const std::string langOpt = isCpp ? "-x c++" : "-x c";
const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), emptyString);
const std::string clangcmd = analyzerInfo + ".clang-cmd";
Expand Down
18 changes: 18 additions & 0 deletions test/cli/clang-import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,21 @@ def test_warning(tmpdir): # #12424
assert exitcode == 0, stderr # do not assert
assert stdout == ''
assert stderr == ''


def test_cmd(tmp_path):
test_file_name = 'test.cpp'
test_file = tmp_path / test_file_name
with open(test_file, 'wt') as f:
f.write('')

inc_path = tmp_path / 'inc'
os.makedirs(inc_path)

exitcode, stdout, stderr = cppcheck(['--enable=information', '--verbose', '--clang', '-x', 'c', '--std=c89', '-Iinc', '-DDEF', test_file_name], cwd=tmp_path)
assert exitcode == 0, stderr if not stdout else stdout
assert stderr == ''
assert stdout.splitlines() == [
'Checking {} ...'.format(test_file),
'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics -x c -std=c89 -Iinc/ -DDEF=1 {}'.format(test_file_name)
]

0 comments on commit 7642b93

Please sign in to comment.