Skip to content
Merged
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
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;
Copy link
Copy Markdown
Collaborator

@chrchr-github chrchr-github Sep 24, 2024

Choose a reason for hiding this comment

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

isCpp could be initialized with (mSettings.enforcedLang == Standards::CPP);
Or even make it const and use a ternary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That code will go away when the language is moved into FileWithDetails.

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
2 changes: 0 additions & 2 deletions test/cli/clang-import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,10 @@ def test_cmd_def(tmp_path):
__test_cmd(tmp_path, 'test.cpp',['-DDEF'], '-x c++ -DDEF=1')


@pytest.mark.xfail(strict=True)
def test_cmd_enforce_c(tmp_path): # #13128
__test_cmd(tmp_path, 'test.cpp',['-x', 'c'], '-x c')


@pytest.mark.xfail(strict=True)
def test_cmd_enforce_cpp(tmp_path): # #13128
__test_cmd(tmp_path, 'test.c',['-x', 'c++'], '-x c++')

Expand Down