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();"));