diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3465928e8..63ca7b162 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4050,7 +4050,7 @@ void Tokenizer::setVarIdPass1() const Token *end = tok->findClosingBracket(); while (tok != end) { if (tok->isName() && !(Token::simpleMatch(tok->next(), "<") && - Token::Match(tok->tokAt(-2), "std :: %name%"))) { + Token::Match(tok->tokAt(-1), ":: %name%"))) { const std::map::const_iterator it = variableMap.find(tok->str()); if (it != variableMap.end()) tok->varId(it->second); diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 4ae645092..862aabeef 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -2339,13 +2339,21 @@ private: tokenize("VertexArrayIterator attrPos = m_AttributePos.GetIterator();")); } - void varid_templateParameter() { // #7046 set varid for "X": std::array Y; - const char code[] = "const int X = 0;\n" - "std::array Y;\n"; + void varid_templateParameter() { + { + const char code[] = "const int X = 0;\n" // #7046 set varid for "X": std::array Y; + "std::array Y;\n"; - ASSERT_EQUALS("1: const int X@1 = 0 ;\n" - "2: std :: array < int , X@1 > Y@2 ;\n", - tokenize(code)); + ASSERT_EQUALS("1: const int X@1 = 0 ;\n" + "2: std :: array < int , X@1 > Y@2 ;\n", + tokenize(code)); + } + { + const char code[] = "std::optional> Foo;\n"; // #11003 + + ASSERT_EQUALS("1: std :: optional < N :: Foo < A > > Foo@1 ;\n", + tokenize(code)); + } } void varid_templateUsing() { // #5781 #7273