From 1f44fbbeb76d30a052119e67fa58bedfda8e50ac Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 7 Jul 2023 11:52:35 +0200 Subject: [PATCH] Fix #11818 FP constParameterReference with stream write --- 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 c3d70d0cfc0..268b9535b1e 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3033,7 +3033,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")) return false; if (op->str() == "&" && parent->astParent()) return false; diff --git a/test/testother.cpp b/test/testother.cpp index 33fe01276e1..1c0fb8b9fdd 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3270,6 +3270,12 @@ class TestOther : public TestFixture { " const int* p = s.g();\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S { int x; };\n" // #11818 + "std::istream& f(std::istream& is, S& s) {\n" + " return is >> s.x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void constParameterCallback() {