diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3005842ab..5dcd16aaa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2875,15 +2875,15 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::mapprevious(), "%or%|%oror%|&&|&|^|+|-|*|/")) return false; - const Token * tok3 = tok2->findClosingBracket(); - if (tok3 == nullptr) { /* Ticket #8151 */ + const Token * const closingBracket = tok2->findClosingBracket(); + if (closingBracket == nullptr) { /* Ticket #8151 */ throw tok2; } - tok2 = tok3; + tok2 = closingBracket; if (tok2->str() != ">") break; singleNameCount = 1; - if (Token::Match(tok2, "> %name% %or%|%oror%|&&|&|^|+|-|*|/")) + if (Token::Match(tok2, "> %name% %or%|%oror%|&&|&|^|+|-|*|/") && !Token::Match(tok2, "> const [*&]")) return false; if (Token::Match(tok2, "> %name% )")) { if (Token::Match(tok2->linkAt(2)->previous(), "if|for|while (")) diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 3beafda5e..d01939083 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -93,6 +93,7 @@ private: TEST_CASE(varid60); // #7267 cast '(unsigned x)10' TEST_CASE(varid61); // #4988 inline function TEST_CASE(varid62); + TEST_CASE(varid63); TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete" TEST_CASE(varidFunctionCall1); @@ -1115,6 +1116,12 @@ private: ASSERT_EQUALS("same varid", compareVaridsForVariable(code, "x")); } + void varid63() { + const char code[] = "void f(boost::optional const& x) {}"; + const char expected[] = "1: void f ( boost :: optional < int > const & x@1 ) { }\n"; + ASSERT_EQUALS(expected, tokenize(code, false)); + } + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n"