@@ -658,10 +658,10 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
658658 mErrorLogger .reportOut (std::string (" Checking " ) + file.spath () + " ..." , Color::FgGreen);
659659
660660 // TODO: get language from FileWithDetails object
661- const std::string analyzerInfo = mSettings . buildDir . empty () ? std::string () : AnalyzerInformation::getAnalyzerInfoFile ( mSettings . buildDir , file. spath (), " " ) ;
662- const std::string clangcmd = analyzerInfo + " .clang-cmd " ;
663- const std::string clangStderr = analyzerInfo + " .clang-stderr" ;
664- const std::string clangAst = analyzerInfo + " .clang-ast " ;
661+ std::string clangStderr ;
662+ if (! mSettings . buildDir . empty ())
663+ clangStderr = AnalyzerInformation::getAnalyzerInfoFile ( mSettings . buildDir , file. spath (), " " ) + " .clang-stderr" ;
664+
665665 std::string exe = mSettings .clangExecutable ;
666666#ifdef _WIN32
667667 // append .exe if it is not a path
@@ -673,17 +673,17 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
673673 const std::string args2 = " -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics " +
674674 getClangFlags (Path::identify (file.spath (), mSettings .cppHeaderProbe )) +
675675 file.spath ();
676- const std::string redirect2 = analyzerInfo.empty () ? std::string (" 2>&1" ) : (" 2> " + clangStderr);
677- if (!mSettings .buildDir .empty ()) {
678- std::ofstream fout (clangcmd);
679- fout << exe << " " << args2 << " " << redirect2 << std::endl;
680- }
676+ const std::string redirect2 = clangStderr.empty () ? " 2>&1" : (" 2> " + clangStderr);
681677 if (mSettings .verbose && !mSettings .quiet ) {
682678 mErrorLogger .reportOut (exe + " " + args2);
683679 }
684680
685681 std::string output2;
686682 const int exitcode = mExecuteCommand (exe,split (args2),redirect2,output2);
683+ if (mSettings .debugClangOutput ) {
684+ std::cout << output2 << std::endl;
685+ }
686+ // TODO: this might also fail if compiler errors are encountered - we should report them properly
687687 if (exitcode != EXIT_SUCCESS) {
688688 // TODO: report as proper error
689689 std::cerr << " Failed to execute '" << exe << " " << args2 << " " << redirect2 << " ' - (exitcode: " << exitcode << " / output: " << output2 << " )" << std::endl;
@@ -696,29 +696,22 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
696696 return 0 ; // TODO: report as failure?
697697 }
698698
699+ const auto reportError = [this ](const ErrorMessage& errorMessage) {
700+ mErrorLogger .reportErr (errorMessage);
701+ };
702+
699703 // Ensure there are not syntax errors...
700704 std::vector<ErrorMessage> compilerWarnings;
701- if (!mSettings . buildDir .empty ()) {
705+ if (!clangStderr .empty ()) {
702706 std::ifstream fin (clangStderr);
703- auto reportError = [this ](const ErrorMessage& errorMessage) {
704- mErrorLogger .reportErr (errorMessage);
705- };
706707 if (reportClangErrors (fin, reportError, compilerWarnings))
707708 return 0 ; // TODO: report as failure?
708709 } else {
709710 std::istringstream istr (output2);
710- auto reportError = [this ](const ErrorMessage& errorMessage) {
711- mErrorLogger .reportErr (errorMessage);
712- };
713711 if (reportClangErrors (istr, reportError, compilerWarnings))
714712 return 0 ; // TODO: report as failure?
715713 }
716714
717- if (!mSettings .buildDir .empty ()) {
718- std::ofstream fout (clangAst);
719- fout << output2 << std::endl;
720- }
721-
722715 try {
723716 Tokenizer tokenizer (mSettings , mErrorLogger );
724717 tokenizer.list .appendFileIfNew (file.spath ());
0 commit comments