From 068b0b246c726629e42f8d02f37ea2366e62d1a3 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 13 Sep 2019 01:33:30 -0500 Subject: [PATCH] Fix issue 9352: FP constParameter and constVariable for auto& in combination with ternary ?: operator (#2173) --- lib/astutils.cpp | 3 +++ test/testother.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 9ff7d4884..383bf7806 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1100,6 +1100,9 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, (Token::simpleMatch(tok2->astParent(), "[") && tok2 == tok2->astParent()->astOperand1())) tok2 = tok2->astParent(); + while (Token::simpleMatch(tok2->astParent(), "?") || (Token::simpleMatch(tok2->astParent(), ":") && Token::simpleMatch(tok2->astParent()->astParent(), "?"))) + tok2 = tok2->astParent(); + if (Token::Match(tok2->astParent(), "++|--")) return true; diff --git a/test/testother.cpp b/test/testother.cpp index 73726c00e..389c39b8f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1906,6 +1906,13 @@ private: "};\n"); ASSERT_EQUALS("", errout.str()); + check("void f(bool b, int& x, int& y) {\n" + " auto& z = x;\n" + " auto& w = b ? y : z;\n" + " w = 1;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void e();\n" "void g(void);\n" "void h(void);\n"