Skip to content

Commit 0eccffe

Browse files
committed
--clang; require that --cppcheck-build-dir. output files are needed.
1 parent 7d4bd57 commit 0eccffe

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,16 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
916916
}
917917
}
918918

919+
if (mSettings->clang) {
920+
if (mSettings->buildDir.empty()) {
921+
printMessage("If --clang is used then --cppcheck-build-dir must be specified also");
922+
return false;
923+
}
924+
std::ofstream fout(mSettings->buildDir + "/__temp__.c");
925+
fout << "int x;\n";
926+
}
927+
928+
919929
// Default template format..
920930
if (mSettings->templateFormat.empty()) {
921931
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";

lib/cppcheck.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,11 @@ unsigned int CppCheck::check(const std::string &path)
254254
mErrorLogger.reportOut(std::string("Checking ") + path + "...");
255255

256256
const std::string clang = Path::isCPP(path) ? "clang++" : "clang";
257+
const std::string temp = mSettings.buildDir + "/__temp__.c";
258+
const std::string stderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-stderr";
257259

258260
/* Experimental: import clang ast dump */
259-
std::ofstream fout("__temp__.c");
260-
fout << "int x;\n";
261-
fout.close();
262-
const std::string cmd1 = clang + " -v -fsyntax-only __temp__.c 2>&1";
261+
const std::string cmd1 = clang + " -v -fsyntax-only " + temp + " 2>&1";
263262
const std::pair<bool, std::string> res1 = executeCommand(cmd1);
264263
if (!res1.first) {
265264
std::cerr << "Failed to execute '" + cmd1 + "'" << std::endl;
@@ -285,7 +284,7 @@ unsigned int CppCheck::check(const std::string &path)
285284
for (const std::string &i: mSettings.includePaths)
286285
flags += "-I" + i + " ";
287286

288-
const std::string cmd = clang + " -cc1 -ast-dump " + flags + path;
287+
const std::string cmd = clang + " -cc1 -ast-dump " + flags + path + " 2> " + stderr;
289288
std::pair<bool, std::string> res = executeCommand(cmd);
290289
if (!res.first) {
291290
std::cerr << "Failed to execute '" + cmd + "'" << std::endl;

0 commit comments

Comments
 (0)