From 23e706864e219e4796cf44c0f6cd4c10de67e1b6 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 10 Jun 2020 22:44:59 -0500 Subject: [PATCH] Fix issue 9718: False positive: Parameter can be declared const when written to via stream extraction operator --- lib/astutils.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index d7926d83b11..bff663e0110 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1578,7 +1578,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op) const Token *parent = op; while (parent->astParent() && parent->astParent()->str() == op->str()) parent = parent->astParent(); - if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|!")) + if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!")) return false; if (op->str() == "&" && parent->astParent()) return false; diff --git a/test/testother.cpp b/test/testother.cpp index 654cf673495..69e759fd756 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1977,6 +1977,12 @@ class TestOther : public TestFixture { "}\n"); 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" "void g(void);\n" "void h(void);\n"