diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e7aae58ea..a58b80900 100755 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8369,28 +8369,12 @@ const Token * Tokenizer::findGarbageCode() const for (const Token *tok = tokens(); tok; tok = tok->next()) { if (!Token::simpleMatch(tok, "template <")) continue; - if (tok->previous() && !Token::Match(tok->previous(), "[:;{}]")) + if (tok->previous() && !Token::Match(tok->previous(), "[:;{})]")) return tok; - const Token *tok1 = tok; - tok = tok->tokAt(2); - while (Token::Match(tok,"%name%|*|,|.|(")) { - if (tok->str() == "(") - tok = tok->link(); - tok = tok->next(); - } - if (tok && tok->str() == "=") { - while (tok && !Token::Match(tok, "[;{}]") && !Token::Match(tok, ">|>> %name%")) { - if (tok->str() == "(") - tok = tok->link(); - tok = tok->next(); - } - } + const Token * const tok1 = tok; + tok = tok->next()->findClosingBracket(); if (!tok) return tok1; - if (Token::simpleMatch(tok->previous(), "template <")) - continue; - if (!Token::Match(tok, ">|>>")) - return tok1; if (!Token::Match(tok, ">|>> %name%")) return tok->next() ? tok->next() : tok1; } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 6e1a8339b..089cd110e 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1008,13 +1008,13 @@ private: void garbageCode134() { // Ticket #5605, #5759, #5762, #5774, #5823, #6059 ASSERT_THROW(checkCode("foo() template struct tuple Args> tuple { } main() { foo(); }"), InternalError); - ASSERT_THROW(checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"), InternalError); - ASSERT_THROW(checkCode("() template < T = typename = x > struct a {} { f () }"), InternalError); + checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"); + checkCode("() template < T = typename = x > struct a {} { f () }"); checkCode("template < T = typename = > struct a { f }"); - ASSERT_THROW(checkCode("struct S { int i, j; }; " - "template struct X {}; " - "X<&S::i, int> x = X<&S::i, int>(); " - "X<&S::j, int> y = X<&S::j, int>(); "), InternalError); + checkCode("struct S { int i, j; }; " + "template struct X {}; " + "X<&S::i, int> x = X<&S::i, int>(); " + "X<&S::j, int> y = X<&S::j, int>(); "); checkCode("template struct A {}; " "template <> struct A {}; " "void foo(const void* f = 0) {}");