@@ -753,18 +753,10 @@ bool Preprocessor::hasErrors(const simplecpp::Output &output)
753753 return false ;
754754}
755755
756- bool Preprocessor::hasErrors (const simplecpp::OutputList &outputList)
757- {
758- const auto it = std::find_if (outputList.cbegin (), outputList.cend (), [](const simplecpp::Output &output) {
759- return hasErrors (output);
760- });
761- return it != outputList.cend ();
762- }
763-
764- void Preprocessor::handleErrors (const simplecpp::OutputList& outputList, bool throwError)
756+ bool Preprocessor::handleErrors (const simplecpp::OutputList& outputList, bool throwError)
765757{
766758 const bool showerror = (!mSettings .userDefines .empty () && !mSettings .force );
767- reportOutput (outputList, showerror);
759+ const bool hasError = reportOutput (outputList, showerror);
768760 if (throwError) {
769761 const auto it = std::find_if (outputList.cbegin (), outputList.cend (), [](const simplecpp::Output &output){
770762 return hasErrors (output);
@@ -773,6 +765,7 @@ void Preprocessor::handleErrors(const simplecpp::OutputList& outputList, bool th
773765 throw *it;
774766 }
775767 }
768+ return hasError;
776769}
777770
778771bool Preprocessor::loadFiles (std::vector<std::string> &files)
@@ -781,8 +774,7 @@ bool Preprocessor::loadFiles(std::vector<std::string> &files)
781774
782775 simplecpp::OutputList outputList;
783776 mFileCache = simplecpp::load (mTokens , files, dui, &outputList);
784- handleErrors (outputList, false );
785- return !hasErrors (outputList);
777+ return !handleErrors (outputList, false );
786778}
787779
788780void Preprocessor::removeComments ()
@@ -825,7 +817,7 @@ simplecpp::TokenList Preprocessor::preprocess(const std::string &cfg, std::vecto
825817 mMacroUsage = std::move (macroUsage);
826818 mIfCond = std::move (ifCond);
827819
828- handleErrors (outputList, throwError);
820+ ( void ) handleErrors (outputList, throwError);
829821
830822 tokens2.removeComments ();
831823
@@ -859,18 +851,22 @@ std::string Preprocessor::getcode(const std::string &cfg, std::vector<std::strin
859851 return ret.str ();
860852}
861853
862- void Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
854+ bool Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
863855{
856+ bool hasError = false ;
857+
864858 for (const simplecpp::Output &out : outputList) {
865859 switch (out.type ) {
866860 case simplecpp::Output::ERROR:
861+ hasError = true ;
867862 if (!startsWith (out.msg ," #error" ) || showerror)
868863 error (out.location .file (), out.location .line , out.msg );
869864 break ;
870865 case simplecpp::Output::WARNING:
871866 case simplecpp::Output::PORTABILITY_BACKSLASH:
872867 break ;
873868 case simplecpp::Output::MISSING_HEADER: {
869+ // not considered an "error"
874870 const std::string::size_type pos1 = out.msg .find_first_of (" <\" " );
875871 const std::string::size_type pos2 = out.msg .find_first_of (" >\" " , pos1 + 1U );
876872 if (pos1 < pos2 && pos2 != std::string::npos)
@@ -880,15 +876,19 @@ void Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
880876 case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
881877 case simplecpp::Output::SYNTAX_ERROR:
882878 case simplecpp::Output::UNHANDLED_CHAR_ERROR:
879+ hasError = true ;
883880 error (out.location .file (), out.location .line , out.msg );
884881 break ;
885882 case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
886883 case simplecpp::Output::FILE_NOT_FOUND:
887884 case simplecpp::Output::DUI_ERROR:
885+ hasError = true ;
888886 error (" " , 0 , out.msg );
889887 break ;
890888 }
891889 }
890+
891+ return hasError;
892892}
893893
894894void Preprocessor::error (const std::string &filename, unsigned int linenr, const std::string &msg)
0 commit comments