File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2788,6 +2788,20 @@ void Tokenizer::setVarId()
27882788
27892789 if (decl) {
27902790 variableId[prev2->str ()] = ++_varId;
2791+
2792+ // set varid for template parameters..
2793+ tok = tok->next ();
2794+ while (Token::Match (tok, " %name%|::" ))
2795+ tok = tok->next ();
2796+ if (tok && tok->str () == " <" ) {
2797+ const Token *end = tok->findClosingBracket ();
2798+ while (tok != end) {
2799+ if (tok->isName () && variableId.find (tok->str ()) != variableId.end ())
2800+ tok->varId (variableId[tok->str ()]);
2801+ tok = tok->next ();
2802+ }
2803+ }
2804+
27912805 tok = tok2->previous ();
27922806 }
27932807 }
Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ class TestVarID : public TestFixture {
135135 TEST_CASE (varid_templatePtr); // #4319
136136 TEST_CASE (varid_templateNamespaceFuncPtr); // #4172
137137 TEST_CASE (varid_templateArray);
138+ TEST_CASE (varid_templateParameter); // #7046 set varid for "X": std::array<int,X> Y;
138139 TEST_CASE (varid_cppcast); // #6190
139140 TEST_CASE (varid_variadicFunc);
140141 TEST_CASE (varid_typename); // #4644
@@ -2135,6 +2136,16 @@ class TestVarID : public TestFixture {
21352136 tokenize (" VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();" ));
21362137 }
21372138
2139+ void varid_templateParameter () { // #7046 set varid for "X": std::array<int,X> Y;
2140+ const char code[] = " const int X = 0;\n "
2141+ " std::array<int,X> Y;\n " ;
2142+
2143+ ASSERT_EQUALS (" \n\n ##file 0\n "
2144+ " 1: const int X@1 = 0 ;\n "
2145+ " 2: std :: array < int , X@1 > Y@2 ;\n " ,
2146+ tokenize (code));
2147+ }
2148+
21382149 void varid_cppcast () {
21392150 ASSERT_EQUALS (" \n\n ##file 0\n 1: const_cast < int * > ( code ) [ 0 ] = 0 ;\n " ,
21402151 tokenize (" const_cast<int *>(code)[0] = 0;" ));
You can’t perform that action at this time.
0 commit comments