@@ -857,6 +857,9 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std:
857857 toolinfo << (mSettings .severity .isEnabled (Severity::portability) ? ' p' : ' ' );
858858 toolinfo << (mSettings .severity .isEnabled (Severity::information) ? ' i' : ' ' );
859859 toolinfo << mSettings .userDefines ;
860+ toolinfo << (mSettings .checkConfiguration ? ' c' : ' ' ); // --check-config
861+ toolinfo << (mSettings .force ? ' f' : ' ' );
862+ toolinfo << mSettings .maxConfigs ;
860863 toolinfo << std::to_string (static_cast <std::uint8_t >(mSettings .checkLevel ));
861864 for (const auto &a : mSettings .addonInfos ) {
862865 toolinfo << a.name ;
@@ -1041,6 +1044,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10411044 for (const std::string &config : configurations)
10421045 (void )preprocessor.getcode (config, files, false );
10431046
1047+ if (configurations.size () > mSettings .maxConfigs )
1048+ tooManyConfigsError (Path::toNativeSeparators (file.spath ()), configurations.size ());
1049+
10441050 if (analyzerInformation)
10451051 mLogger ->setAnalyzerInfo (nullptr );
10461052 return 0 ;
@@ -1060,14 +1066,6 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10601066 }
10611067#endif
10621068
1063- if (!mSettings .force && configurations.size () > mSettings .maxConfigs ) {
1064- if (mSettings .severity .isEnabled (Severity::information)) {
1065- tooManyConfigsError (Path::toNativeSeparators (file.spath ()),configurations.size ());
1066- } else {
1067- mTooManyConfigs = true ;
1068- }
1069- }
1070-
10711069 FilesDeleter filesDeleter;
10721070
10731071 // write dump file xml prolog
@@ -1092,8 +1090,18 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10921090
10931091 // Check only a few configurations (default 12), after that bail out, unless --force
10941092 // was used.
1095- if (!mSettings .force && ++checkCount > mSettings .maxConfigs )
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
1096+ // the information message is not reported, the whole purpose of setting i.e. --max-configs=1 is to
1097+ // skip configurations. When --check-config is used then tooManyConfigs will be reported even if the
1098+ // value is non-default.
1099+ const Settings defaultSettings;
1100+ if (mSettings .maxConfigs == defaultSettings.maxConfigs && mSettings .severity .isEnabled (Severity::information))
1101+ tooManyConfigsError (Path::toNativeSeparators (file.spath ()), configurations.size ());
1102+
10961103 break ;
1104+ }
10971105
10981106 std::string currentConfig;
10991107
@@ -1630,32 +1638,14 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
16301638
16311639void CppCheck::tooManyConfigsError (const std::string &file, const int numberOfConfigurations)
16321640{
1633- if (!mSettings .severity .isEnabled (Severity::information) && !mTooManyConfigs )
1634- return ;
1635-
1636- mTooManyConfigs = false ;
1637-
1638- if (mSettings .severity .isEnabled (Severity::information) && file.empty ())
1639- return ;
1640-
16411641 std::list<ErrorMessage::FileLocation> loclist;
16421642 if (!file.empty ()) {
16431643 loclist.emplace_back (file, 0 , 0 );
16441644 }
16451645
16461646 std::ostringstream msg;
1647- msg << " Too many #ifdef configurations - cppcheck only checks " << mSettings .maxConfigs ;
1648- if (numberOfConfigurations > mSettings .maxConfigs )
1649- msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n " ;
1650- if (file.empty ())
1651- msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n " ;
1652- msg << " The checking of the file will be interrupted because there are too many "
1653- " #ifdef configurations. Checking of all #ifdef configurations can be forced "
1654- " by --force command line option or from GUI preferences. However that may "
1655- " increase the checking time." ;
1656- if (file.empty ())
1657- msg << " For more details, use --enable=information." ;
1658-
1647+ msg << " Too many #ifdef configurations - cppcheck only checks " << mSettings .maxConfigs
1648+ << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations." ;
16591649
16601650 ErrorMessage errmsg (std::move (loclist),
16611651 " " ,
@@ -1669,8 +1659,6 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo
16691659
16701660void CppCheck::purgedConfigurationMessage (const std::string &file, const std::string& configuration)
16711661{
1672- mTooManyConfigs = false ;
1673-
16741662 if (mSettings .severity .isEnabled (Severity::information) && file.empty ())
16751663 return ;
16761664
@@ -1699,7 +1687,6 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
16991687
17001688 CppCheck cppcheck (settings, supprs, errorlogger, true , nullptr );
17011689 cppcheck.purgedConfigurationMessage (" " ," " );
1702- cppcheck.mTooManyConfigs = true ;
17031690 cppcheck.tooManyConfigsError (" " ,0U );
17041691 // TODO: add functions to get remaining error messages
17051692
0 commit comments