Fix 9766: False positive; suspicious operator is written in declaration (#3476)

This commit is contained in:
Paul Fultz II 2021-10-03 02:59:51 -05:00 committed by GitHub
parent f0f4ee7d91
commit fc6a791a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

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

View File

@ -4589,6 +4589,11 @@ private:
" for (p = path; *p++;) ;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" std::array<std::array<double,3>,3> array;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void duplicateBranch() {

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(template4); // #9805
TEST_CASE(template5);
TEST_CASE(template6); // #10475 crash
TEST_CASE(template7); // #9766 crash
TEST_CASE(throwIsNotAFunction);
TEST_CASE(unusedError);
TEST_CASE(unusedMain);
@ -268,6 +269,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void template7()
{ // #9766
check("void f() {\n"
" std::array<std::array<double,3>,3> array;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
}
void throwIsNotAFunction() {
check("struct A {void f() const throw () {}}; int main() {A a; a.f();}");
ASSERT_EQUALS("", errout.str());