diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 7119e036f..64697a786 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2930,6 +2930,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( numberOfTemplateInstantiations = mTemplateInstantiations.size(); ++recursiveCount; if (recursiveCount > mSettings->maxTemplateRecursion) { + std::list typeStringsUsedInTemplateInstantiation; + const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">"; + const std::list callstack(1, instantiation.token()); const ErrorMessage errmsg(callstack, &mTokenizer->list, @@ -2937,7 +2940,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( "templateRecursion", "TemplateSimplifier: max template recursion (" + MathLib::toString(mSettings->maxTemplateRecursion) - + ") reached for template '"+instantiation.fullName()+"'. You might want to limit Cppcheck recursion.", + + ") reached for template '"+typeForNewName+"'. You might want to limit Cppcheck recursion.", false); if (mErrorLogger && mSettings->isEnabled(Settings::INFORMATION)) mErrorLogger->reportErr(errmsg); diff --git a/man/manual.md b/man/manual.md index dbb64c596..a225ba7d3 100644 --- a/man/manual.md +++ b/man/manual.md @@ -167,10 +167,13 @@ Example code: Cppcheck output: - test.cpp:4:5: information: TemplateSimplifier: max template recursion (100) reached for template 'a'. You might want to limit Cppcheck recursion. [templateRecursion] + test.cpp:4:5: information: TemplateSimplifier: max template recursion (100) reached for template 'a<101>'. You might want to limit Cppcheck recursion. [templateRecursion] a(); ^ +As you can see Cppcheck has instantiated `a` until `a<101>` was reached +and then it bails out. + One way to make Cppcheck analysis faster is to limit the recursion with a template specialisation. For instance: