Fix 11050: False positive: unreadVariable for class variable when another function uses the same variable name (#4121)

This commit is contained in:
Paul Fultz II 2022-05-22 02:20:32 -05:00 committed by GitHub
parent c9073682ca
commit e2c35abde5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -3750,6 +3750,13 @@ void Tokenizer::setVarIdPass1()
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->isOp())
continue;
if (isCPP() && Token::simpleMatch(tok, "template <")) {
Token* closingBracket = tok->next()->findClosingBracket();
if (closingBracket)
tok = closingBracket;
continue;
}
if (tok == functionDeclEndToken) {
functionDeclEndStack.pop();
functionDeclEndToken = functionDeclEndStack.empty() ? nullptr : functionDeclEndStack.top();

View File

@ -153,6 +153,7 @@ private:
TEST_CASE(varid_templateNamespaceFuncPtr); // #4172
TEST_CASE(varid_templateArray);
TEST_CASE(varid_templateParameter); // #7046 set varid for "X": std::array<int,X> Y;
TEST_CASE(varid_templateParameterFunctionPointer); // #11050
TEST_CASE(varid_templateUsing); // #5781 #7273
TEST_CASE(varid_not_template_in_condition); // #7988
TEST_CASE(varid_cppcast); // #6190
@ -2358,6 +2359,17 @@ private:
}
}
void varid_templateParameterFunctionPointer() {
{
const char code[] = "template <class, void (*F)()>\n"
"struct a;\n";
ASSERT_EQUALS("1: template < class , void ( * F ) ( ) >\n"
"2: struct a ;\n",
tokenize(code));
}
}
void varid_templateUsing() { // #5781 #7273
const char code[] = "template<class T> using X = Y<T,4>;\n"
"X<int> x;";