Fix #11003 cppcheckError with nested template arguments (#4049)

This commit is contained in:
chrchr-github 2022-04-25 22:23:06 +02:00 committed by GitHub
parent 1bc0317719
commit 961ecfbe33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -4050,7 +4050,7 @@ void Tokenizer::setVarIdPass1()
const Token *end = tok->findClosingBracket(); const Token *end = tok->findClosingBracket();
while (tok != end) { while (tok != end) {
if (tok->isName() && !(Token::simpleMatch(tok->next(), "<") && if (tok->isName() && !(Token::simpleMatch(tok->next(), "<") &&
Token::Match(tok->tokAt(-2), "std :: %name%"))) { Token::Match(tok->tokAt(-1), ":: %name%"))) {
const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str()); const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
if (it != variableMap.end()) if (it != variableMap.end())
tok->varId(it->second); tok->varId(it->second);

View File

@ -2339,14 +2339,22 @@ private:
tokenize("VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();")); tokenize("VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();"));
} }
void varid_templateParameter() { // #7046 set varid for "X": std::array<int,X> Y; void varid_templateParameter() {
const char code[] = "const int X = 0;\n" {
const char code[] = "const int X = 0;\n" // #7046 set varid for "X": std::array<int,X> Y;
"std::array<int,X> Y;\n"; "std::array<int,X> Y;\n";
ASSERT_EQUALS("1: const int X@1 = 0 ;\n" ASSERT_EQUALS("1: const int X@1 = 0 ;\n"
"2: std :: array < int , X@1 > Y@2 ;\n", "2: std :: array < int , X@1 > Y@2 ;\n",
tokenize(code)); tokenize(code));
} }
{
const char code[] = "std::optional<N::Foo<A>> Foo;\n"; // #11003
ASSERT_EQUALS("1: std :: optional < N :: Foo < A > > Foo@1 ;\n",
tokenize(code));
}
}
void varid_templateUsing() { // #5781 #7273 void varid_templateUsing() { // #5781 #7273
const char code[] = "template<class T> using X = Y<T,4>;\n" const char code[] = "template<class T> using X = Y<T,4>;\n"