From 195da2b3d2db00adde6b73df27e3685fca754939 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 14 May 2019 01:57:36 -0500 Subject: [PATCH] Fix issue 8993: False positive duplicateCondition related to auto (#1831) --- lib/symboldatabase.cpp | 2 ++ test/testcondition.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9299b2470..fadcbebc2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4925,6 +4925,8 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype) vt2_.pointer = 1; if ((vt.constness & (1 << vt2->pointer)) != 0) vt2_.constness |= (1 << vt2->pointer); + if (!Token::Match(autoTok->tokAt(1), "*|&")) + vt2_.constness = vt.constness; var->setValueType(vt2_); if (vt2->typeScope && vt2->typeScope->definedType) { var->type(vt2->typeScope->definedType); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 833fb4a14..4c49c34ed 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2978,6 +2978,14 @@ private: " if (b) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #8993 + check("void f(const std::string& x) {\n" + " auto y = x;\n" + " if (x.empty()) y = \"1\";\n" + " if (y.empty()) return;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void checkInvalidTestForOverflow() {