TemplateSimplifier; Clarify information message when max recursion limit is reached
This commit is contained in:
parent
262f44e76a
commit
98bf0d41aa
|
@ -2930,6 +2930,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
|||
numberOfTemplateInstantiations = mTemplateInstantiations.size();
|
||||
++recursiveCount;
|
||||
if (recursiveCount > mSettings->maxTemplateRecursion) {
|
||||
std::list<std::string> typeStringsUsedInTemplateInstantiation;
|
||||
const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">";
|
||||
|
||||
const std::list<const Token *> 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);
|
||||
|
|
|
@ -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<i+1>();
|
||||
^
|
||||
|
||||
As you can see Cppcheck has instantiated `a<i+1>` 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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue