In the following scenario cppcheck will fail to fix the angle brackets, causing an assertion failure later on in TemplateSimplifier#getTemplateNamePosition:
voidtemplate154(){constcharcode[]="template <typename S, enable_if_t<(is_compile_string<S>::value), int>> void i(S s);";constcharexp[]="template < typename S , enable_if_t < ( is_compile_string < S > :: value ) , int > > void i ( S s ) ;";ASSERT_EQUALS(exp,tok(code));}
The issue can be fixed with the following workaround (although I doubt this is the correct solution):
--- c/lib/templatesimplifier.cpp+++ w/lib/templatesimplifier.cpp@@ -514,7 +514,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
return 0;
// num/type ..
- if (!tok->isNumber() && tok->tokType() != Token::eChar && !tok->isName() && !tok->isOp())+ if (!tok->isNumber() && tok->tokType() != Token::eChar && !tok->isName() && !tok->isOp() && level == 0)
return 0;
tok = tok->next();
if (!tok)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the detailed report.
I have created a ticket in Trac.
I am not familiar with such code, how do you compile it? What headers are needed to get this compiled (with -fsyntax-only)? I guess <type_traits>, but that is obviously not enough.
Last edit: versat 2019-11-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the following scenario cppcheck will fail to fix the angle brackets, causing an assertion failure later on in
TemplateSimplifier#getTemplateNamePosition
:Output from cppheck:
Here is a test case for
TestSimplifyTemplate
:The issue can be fixed with the following workaround (although I doubt this is the correct solution):
Thanks for the detailed report.
I have created a ticket in Trac.
I am not familiar with such code, how do you compile it? What headers are needed to get this compiled (with
-fsyntax-only
)? I guess<type_traits>
, but that is obviously not enough.Last edit: versat 2019-11-28
I stumbled on this issue in a file included from spdlog (https://github.com/gabime/spdlog/blob/v1.x/include/spdlog/fmt/bundled/format.h)
line 2567.
It looks like the key to reproducing this is using these struct defs:
You should be able to reproduce the problem in that code base with
cppcheck -I include --enable=all --inconclusive src/spdlog.cpp
Last edit: Wesley King 2019-11-28