Skip to content

Commit 03b41ac

Browse files
authored
Fix issue 9718: False positive: Parameter can be declared const when written to via stream extraction operator (#2677)
1 parent 6600453 commit 03b41ac

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op)
15781578
const Token *parent = op;
15791579
while (parent->astParent() && parent->astParent()->str() == op->str())
15801580
parent = parent->astParent();
1581-
if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|!"))
1581+
if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!"))
15821582
return false;
15831583
if (op->str() == "&" && parent->astParent())
15841584
return false;

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,12 @@ class TestOther : public TestFixture {
19771977
"}\n");
19781978
ASSERT_EQUALS("", errout.str());
19791979

1980+
check("bool from_string(int& t, const std::string& s) {\n"
1981+
" std::istringstream iss(s);\n"
1982+
" return !(iss >> t).fail();\n"
1983+
"}\n");
1984+
ASSERT_EQUALS("", errout.str());
1985+
19801986
check("void e();\n"
19811987
"void g(void);\n"
19821988
"void h(void);\n"

0 commit comments

Comments
 (0)