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() {