Fix issue 9718: False positive: Parameter can be declared const when written to via stream extraction operator (#2677)

This commit is contained in:
Paul Fultz II 2020-06-13 02:20:40 -05:00 committed by GitHub
parent 6600453b44
commit 03b41ac987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1578,7 +1578,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op)
const Token *parent = op; const Token *parent = op;
while (parent->astParent() && parent->astParent()->str() == op->str()) while (parent->astParent() && parent->astParent()->str() == op->str())
parent = parent->astParent(); parent = parent->astParent();
if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|!")) if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!"))
return false; return false;
if (op->str() == "&" && parent->astParent()) if (op->str() == "&" && parent->astParent())
return false; return false;

View File

@ -1977,6 +1977,12 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("bool from_string(int& t, const std::string& s) {\n"
" std::istringstream iss(s);\n"
" return !(iss >> t).fail();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void e();\n" check("void e();\n"
"void g(void);\n" "void g(void);\n"
"void h(void);\n" "void h(void);\n"