From 445fd4e6aa908394f0942624aac61614939c2c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 5 Aug 2012 17:11:39 +0200 Subject: [PATCH] Fixed #4010 (error (cppcheckError): Internal error. Token::Match called with varid 0) --- lib/templatesimplifier.cpp | 2 +- test/testsimplifytokens.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index b7fbf0358..b58e26926 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -206,7 +206,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) return 0; // * / const - while (Token::Match(tok, "*|const")) + while (Token::Match(tok, "*|&|const")) tok = tok->next(); // Function pointer.. diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 8bee71a15..08d126ed0 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -124,6 +124,7 @@ private: TEST_CASE(template28); TEST_CASE(template29); // #3449 - don't crash for garbage code TEST_CASE(template30); // #3529 - template < template < .. + TEST_CASE(template31); // #4010 - reference type TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2144,6 +2145,12 @@ private: ASSERT_EQUALS("template < template < class > class A , class B > void f ( ) { }", tok(code)); } + void template31() { + // #4010 - template reference type + const char code[] = "template struct A{}; A a;"; + ASSERT_EQUALS("A a ; struct A { }", tok(code)); + } + void template_unhandled() { // An unhandled template usage should be simplified.. ASSERT_EQUALS("x ( ) ;", tok("x();"));