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();
|
numberOfTemplateInstantiations = mTemplateInstantiations.size();
|
||||||
++recursiveCount;
|
++recursiveCount;
|
||||||
if (recursiveCount > mSettings->maxTemplateRecursion) {
|
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 std::list<const Token *> callstack(1, instantiation.token());
|
||||||
const ErrorMessage errmsg(callstack,
|
const ErrorMessage errmsg(callstack,
|
||||||
&mTokenizer->list,
|
&mTokenizer->list,
|
||||||
|
@ -2937,7 +2940,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
"templateRecursion",
|
"templateRecursion",
|
||||||
"TemplateSimplifier: max template recursion ("
|
"TemplateSimplifier: max template recursion ("
|
||||||
+ MathLib::toString(mSettings->maxTemplateRecursion)
|
+ 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);
|
false);
|
||||||
if (mErrorLogger && mSettings->isEnabled(Settings::INFORMATION))
|
if (mErrorLogger && mSettings->isEnabled(Settings::INFORMATION))
|
||||||
mErrorLogger->reportErr(errmsg);
|
mErrorLogger->reportErr(errmsg);
|
||||||
|
|
|
@ -167,10 +167,13 @@ Example code:
|
||||||
|
|
||||||
Cppcheck output:
|
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>();
|
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
|
One way to make Cppcheck analysis faster is to limit the recursion with a
|
||||||
template specialisation. For instance:
|
template specialisation. For instance:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue