@@ -859,7 +859,7 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std:
859859 toolinfo << mSettings .userDefines ;
860860 toolinfo << (mSettings .checkConfiguration ? ' c' : ' ' ); // --check-config
861861 toolinfo << (mSettings .force ? ' f' : ' ' );
862- toolinfo << mSettings .maxConfigs ;
862+ toolinfo << mSettings .maxConfigsOption ;
863863 toolinfo << std::to_string (static_cast <std::uint8_t >(mSettings .checkLevel ));
864864 for (const auto &a : mSettings .addonInfos ) {
865865 toolinfo << a.name ;
@@ -908,6 +908,8 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
908908 if (mSettings .checks .isEnabled (Checks::unusedFunction) && !mUnusedFunctionsCheck )
909909 mUnusedFunctionsCheck .reset (new CheckUnusedFunctions ());
910910
911+ const int maxConfigs = mSettings .getMaxConfigs ();
912+
911913 mLogger ->resetExitCode ();
912914
913915 if (Settings::terminated ())
@@ -1032,7 +1034,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10321034
10331035 // Get configurations..
10341036 std::set<std::string> configurations;
1035- if (( mSettings . checkAllConfigurations && mSettings . userDefines . empty ()) || mSettings . force ) {
1037+ if (maxConfigs > 1 ) {
10361038 Timer::run (" Preprocessor::getConfigs" , mSettings .showtime , &s_timerResults, [&]() {
10371039 configurations = preprocessor.getConfigs ();
10381040 });
@@ -1044,7 +1046,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10441046 for (const std::string &config : configurations)
10451047 (void )preprocessor.getcode (config, files, false );
10461048
1047- if (configurations.size () > mSettings . maxConfigs )
1049+ if (configurations.size () > maxConfigs)
10481050 tooManyConfigsError (Path::toNativeSeparators (file.spath ()), configurations.size ());
10491051
10501052 if (analyzerInformation)
@@ -1090,14 +1092,13 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10901092
10911093 // Check only a few configurations (default 12), after that bail out, unless --force
10921094 // was used.
1093- if (!mSettings .force && ++checkCount > mSettings . maxConfigs ) {
1094- // If maxConfigs has default value then report information message that configurations are skipped.
1095- // If maxConfigs does not have default value then the user is explicitly skipping configurations so
1095+ if (!mSettings .force && ++checkCount > maxConfigs) {
1096+ // If maxConfigs is not assigned then report information message that configurations are skipped.
1097+ // If maxConfigs is assigned then the user is explicitly skipping configurations so
10961098 // the information message is not reported, the whole purpose of setting i.e. --max-configs=1 is to
10971099 // skip configurations. When --check-config is used then tooManyConfigs will be reported even if the
10981100 // value is non-default.
1099- const Settings defaultSettings;
1100- if (mSettings .maxConfigs == defaultSettings.maxConfigs && mSettings .severity .isEnabled (Severity::information))
1101+ if (!mSettings .isMaxConfigsAssigned () && mSettings .severity .isEnabled (Severity::information))
11011102 tooManyConfigsError (Path::toNativeSeparators (file.spath ()), configurations.size ());
11021103
11031104 break ;
@@ -1198,7 +1199,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
11981199 }
11991200
12001201 // Skip if we already met the same simplified token list
1201- if (mSettings . force || mSettings . maxConfigs > 1 ) {
1202+ if (maxConfigs > 1 ) {
12021203 const std::size_t hash = tokenizer.list .calculateHash ();
12031204 if (hashes.find (hash) != hashes.end ()) {
12041205 if (mSettings .debugwarnings )
@@ -1644,7 +1645,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo
16441645 }
16451646
16461647 std::ostringstream msg;
1647- msg << " Too many #ifdef configurations - cppcheck only checks " << mSettings .maxConfigs
1648+ msg << " Too many #ifdef configurations - cppcheck only checks " << mSettings .getMaxConfigs ()
16481649 << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations." ;
16491650
16501651 ErrorMessage errmsg (std::move (loclist),
0 commit comments