From 03b41ac9878cc15f483f6aa3f696bab3875be17b Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 13 Jun 2020 02:20:40 -0500 Subject: [PATCH] Fix issue 9718: False positive: Parameter can be declared const when written to via stream extraction operator (#2677) --- 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 d7926d83b..bff663e01 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 654cf6734..69e759fd7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1977,6 +1977,12 @@ private: "}\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"