Skip to content

Commit 961ecfb

Browse files
Fix #11003 cppcheckError with nested template arguments (#4049)
1 parent 1bc0317 commit 961ecfb

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4050,7 +4050,7 @@ void Tokenizer::setVarIdPass1()
40504050
const Token *end = tok->findClosingBracket();
40514051
while (tok != end) {
40524052
if (tok->isName() && !(Token::simpleMatch(tok->next(), "<") &&
4053-
Token::Match(tok->tokAt(-2), "std :: %name%"))) {
4053+
Token::Match(tok->tokAt(-1), ":: %name%"))) {
40544054
const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
40554055
if (it != variableMap.end())
40564056
tok->varId(it->second);

test/testvarid.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,13 +2339,21 @@ class TestVarID : public TestFixture {
23392339
tokenize("VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();"));
23402340
}
23412341

2342-
void varid_templateParameter() { // #7046 set varid for "X": std::array<int,X> Y;
2343-
const char code[] = "const int X = 0;\n"
2344-
"std::array<int,X> Y;\n";
2342+
void varid_templateParameter() {
2343+
{
2344+
const char code[] = "const int X = 0;\n" // #7046 set varid for "X": std::array<int,X> Y;
2345+
"std::array<int,X> Y;\n";
23452346

2346-
ASSERT_EQUALS("1: const int X@1 = 0 ;\n"
2347-
"2: std :: array < int , X@1 > Y@2 ;\n",
2348-
tokenize(code));
2347+
ASSERT_EQUALS("1: const int X@1 = 0 ;\n"
2348+
"2: std :: array < int , X@1 > Y@2 ;\n",
2349+
tokenize(code));
2350+
}
2351+
{
2352+
const char code[] = "std::optional<N::Foo<A>> Foo;\n"; // #11003
2353+
2354+
ASSERT_EQUALS("1: std :: optional < N :: Foo < A > > Foo@1 ;\n",
2355+
tokenize(code));
2356+
}
23492357
}
23502358

23512359
void varid_templateUsing() { // #5781 #7273

0 commit comments

Comments
 (0)