From d0b2ddc056ed1929ad06d024c196129e059d397f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 26 Jun 2020 12:39:55 +0200 Subject: [PATCH] Manual; Tweaked section about template recursion --- man/manual.md | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/man/manual.md b/man/manual.md index 43ea81531..dbb64c596 100644 --- a/man/manual.md +++ b/man/manual.md @@ -150,12 +150,7 @@ Cppcheck instantiates the templates in your code. If your templates are recursive this can lead to slow analysis that uses a lot of memory. Cppcheck will write information messages when there are potential -problems. For instance: - - 2.cpp:3:29: information: TemplateSimplifier: max template recursion (100) reached for template 'a'. You might want to tweak Cppcheck recursion. [templateRecursion] - -One way to limit the recursion is to provide a template specialisation in the -Cppcheck analysis. +problems. Example code: @@ -170,9 +165,31 @@ Example code: a<0>(); } -Template specialisation: +Cppcheck output: + test.cpp:4:5: information: TemplateSimplifier: max template recursion (100) reached for template 'a'. You might want to limit Cppcheck recursion. [templateRecursion] + a(); + ^ + +One way to make Cppcheck analysis faster is to limit the recursion with a +template specialisation. For instance: + + template + void a() + { + a(); + } + + void foo() + { + a<0>(); + } + + #ifdef __cppcheck__ template<> void a<3>() {} + #endif + +You can pass `-D__cppcheck__` when checking this code. # Importing project