Template simplifier; Write information message when recursion limit is reached.

This commit is contained in:
Daniel Marjamäki 2020-06-24 20:30:03 +02:00
parent fdb8cbdb8c
commit 34468f3c1a
3 changed files with 19 additions and 3 deletions

View File

@ -57,6 +57,7 @@ Settings::Settings()
loadAverage(0),
maxConfigs(12),
maxCtuDepth(2),
maxTemplateRecursion(100),
preprocessOnly(false),
quiet(false),
relativePaths(false),

View File

@ -202,15 +202,18 @@ public:
Library library;
/** @brief Load average value */
unsigned int loadAverage;
int loadAverage;
/** @brief Maximum number of configurations to check before bailing.
Default is 12. (--max-configs=N) */
unsigned int maxConfigs;
int maxConfigs;
/** @brief --max-ctu-depth */
int maxCtuDepth;
/** @brief max template recursion */
int maxTemplateRecursion;
/** @brief suppress exitcode */
Suppressions nofail;

View File

@ -2929,7 +2929,19 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
if (numberOfTemplateInstantiations != mTemplateInstantiations.size()) {
numberOfTemplateInstantiations = mTemplateInstantiations.size();
++recursiveCount;
if (recursiveCount > 100) {
if (recursiveCount > mSettings->maxTemplateRecursion) {
const std::list<const Token *> callstack(1, instantiation.token());
const ErrorMessage errmsg(callstack,
&mTokenizer->list,
Severity::information,
"templateRecursion",
"TemplateSimplifier: max template recursion ("
+ MathLib::toString(mSettings->maxTemplateRecursion)
+ ") reached for template '"+instantiation.fullName()+"'. You might want to limit Cppcheck recursion.",
false);
if (mErrorLogger && mSettings->isEnabled(Settings::INFORMATION))
mErrorLogger->reportErr(errmsg);
// bail out..
break;
}