@@ -1133,11 +1133,37 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
11331133 try {
11341134 TokenList tokenlist{mSettings , file.lang ()};
11351135
1136- // Create tokens, skip rest of iteration if failed
1137- Timer::run (" Tokenizer::createTokens" , mSettings .showtime , &s_timerResults, [&]() {
1138- simplecpp::TokenList tokensP = preprocessor.preprocess (currentConfig, files, true );
1139- tokenlist.createTokens (std::move (tokensP));
1140- });
1136+ try {
1137+ // Create tokens, skip rest of iteration if failed
1138+ Timer::run (" Tokenizer::createTokens" , mSettings .showtime , &s_timerResults, [&]() {
1139+ simplecpp::OutputList outputList;
1140+ simplecpp::TokenList tokensP = preprocessor.preprocess (currentConfig, files, outputList);
1141+ Preprocessor::throwFirstError (outputList);
1142+ tokenlist.createTokens (std::move (tokensP));
1143+ });
1144+ } catch (const simplecpp::Output &o) {
1145+ // #error etc during preprocessing
1146+ configurationError.push_back ((currentConfig.empty () ? " \'\' " : currentConfig) + " : [" + o.location .file () + ' :' + std::to_string (o.location .line ) + " ] " + o.msg );
1147+ --checkCount; // don't count invalid configurations
1148+
1149+ if (!hasValidConfig && currCfg == *configurations.rbegin ()) {
1150+ // If there is no valid configuration then report error..
1151+ std::string locfile = Path::fromNativeSeparators (o.location .file ());
1152+ if (mSettings .relativePaths )
1153+ locfile = Path::getRelativePath (locfile, mSettings .basePaths );
1154+
1155+ ErrorMessage::FileLocation loc1 (locfile, o.location .line , o.location .col );
1156+
1157+ ErrorMessage errmsg ({std::move (loc1)},
1158+ file.spath (),
1159+ Severity::error,
1160+ o.msg ,
1161+ " preprocessorErrorDirective" ,
1162+ Certainty::normal);
1163+ mErrorLogger .reportErr (errmsg);
1164+ }
1165+ continue ;
1166+ }
11411167 hasValidConfig = true ;
11421168
11431169 Tokenizer tokenizer (std::move (tokenlist), mErrorLogger );
@@ -1206,29 +1232,6 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
12061232 ErrorMessage errmsg = ErrorMessage::fromInternalError (e, &tokenizer.list , file.spath ());
12071233 mErrorLogger .reportErr (errmsg);
12081234 }
1209- } catch (const simplecpp::Output &o) {
1210- // #error etc during preprocessing
1211- configurationError.push_back ((currentConfig.empty () ? " \'\' " : currentConfig) + " : [" + o.location .file () + ' :' + std::to_string (o.location .line ) + " ] " + o.msg );
1212- --checkCount; // don't count invalid configurations
1213-
1214- if (!hasValidConfig && currCfg == *configurations.rbegin ()) {
1215- // If there is no valid configuration then report error..
1216- std::string locfile = Path::fromNativeSeparators (o.location .file ());
1217- if (mSettings .relativePaths )
1218- locfile = Path::getRelativePath (locfile, mSettings .basePaths );
1219-
1220- ErrorMessage::FileLocation loc1 (locfile, o.location .line , o.location .col );
1221-
1222- ErrorMessage errmsg ({std::move (loc1)},
1223- file.spath (),
1224- Severity::error,
1225- o.msg ,
1226- " preprocessorErrorDirective" ,
1227- Certainty::normal);
1228- mErrorLogger .reportErr (errmsg);
1229- }
1230- continue ;
1231-
12321235 } catch (const TerminateException &) {
12331236 // Analysis is terminated
12341237 if (analyzerInformation)
0 commit comments