diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 22d66674f..658f6e44a 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -240,6 +240,12 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) if (Token::Match(tok, "& ::| %var%")) tok = tok->next(); + // Skip 'typename...' (Ticket #5774) + if (Token::Match(tok, "typename . . .")) { + tok = tok->tokAt(4); + continue; + } + // Skip '=' if (Token::Match(tok, "=")) tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1cae4463b..7f2ae29c6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -418,7 +418,7 @@ private: TEST_CASE(syntax_error); TEST_CASE(syntax_error_templates_1); TEST_CASE(syntax_error_templates_2); - TEST_CASE(syntax_error_templates_3); // Ticket #5605 - invalid template declaration + TEST_CASE(syntax_error_templates_3); // Ticket #5605, #5759, #5762, #5774 TEST_CASE(removeKeywords); @@ -6517,7 +6517,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); // shouldn't segfault } - void syntax_error_templates_3() { // Ticket #5605, #5759, #5762 + void syntax_error_templates_3() { // Ticket #5605, #5759, #5762, #5774 tokenizeAndStringify("foo() template struct tuple Args> tuple { } main() { foo(); }"); tokenizeAndStringify("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"); tokenizeAndStringify("() template < T = typename = x > struct a {} { f () }"); @@ -6529,6 +6529,10 @@ private: tokenizeAndStringify("template struct A {}; " "template <> struct A {}; " "void foo(const void* f = 0) {}"); + tokenizeAndStringify("template struct A { " + " static const int s = 0; " + "}; " + "A a;"); } void removeKeywords() {