Skip to content

Commit 0ff8105

Browse files
committed
Fixed cppcheck-opensource#4074 (Internal error. Token::Match called with varid 0)
1 parent 990340b commit 0ff8105

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
200200
return 0;
201201

202202
// num/type ..
203-
if (!tok->isNumber() && !tok->isName())
203+
if (!tok->isNumber() && tok->type() != Token::eChar && !tok->isName())
204204
return 0;
205205
tok = tok->next();
206206
if (!tok)

test/testsimplifytokens.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class TestSimplifyTokens : public TestFixture {
126126
TEST_CASE(template32); // #3818 - mismatching template not handled well
127127
TEST_CASE(template33); // #3818 - inner templates in template instantiation not handled well
128128
TEST_CASE(template34); // #3706 - namespace => hang
129+
TEST_CASE(template35); // #4074 - A<'x'> a;
129130
TEST_CASE(template_unhandled);
130131
TEST_CASE(template_default_parameter);
131132
TEST_CASE(template_default_type);
@@ -2217,6 +2218,12 @@ class TestSimplifyTokens : public TestFixture {
22172218
"template < > int X < int > :: Y ( 0 ) ;", tok(code));
22182219
}
22192220

2221+
void template35() { // #4074 - "A<'x'> a;" is not recognized as template instantiation
2222+
const char code[] = "template <char c> class A {};\n"
2223+
"A<'x'> a;";
2224+
ASSERT_EQUALS("A<'x'> a ; class A<'x'> { }", tok(code));
2225+
}
2226+
22202227
void template_unhandled() {
22212228
// An unhandled template usage should be simplified..
22222229
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));

0 commit comments

Comments
 (0)