From e2d9aaf23b680b17280c3de17d76b117f5c62115 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 23 May 2021 00:58:19 -0500 Subject: [PATCH] Fix 10286: false positive: uninitvar (#3271) * Fix 10286: false positive: uninitvar * Remove header --- lib/astutils.cpp | 2 +- test/testuninitvar.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index d5a0f8376..0329b66da 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1844,7 +1844,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, } } - if (cpp && Token::simpleMatch(tok2->astParent(), ">>") && tok2->astParent()->astOperand2() == tok2 && isLikelyStreamRead(cpp, tok2->astParent())) + if (cpp && Token::Match(tok2->astParent(), ">>|&") && astIsRHS(tok2) && isLikelyStreamRead(cpp, tok2->astParent())) return true; if (isLikelyStream(cpp, tok2)) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index fb867ce9c..77cdc0214 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4731,6 +4731,17 @@ private: " return (res);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + valueFlowUninit("struct Archive {\n" + " bool isNull;\n" + " friend void operator&(const Archive &, bool &isNull);\n" + "};\n" + "void load(Archive& ar) {\n" + " bool isNull;\n" + " ar & isNull;\n" + " if (!isNull) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void uninitvar_ipa() {