diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 22a8c463e..1d6a286ae 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4743,10 +4743,13 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype) if (isconst) varvt.constness |= 1; setValueType(parent->previous(), varvt); - const_cast(parent->previous()->variable())->setFlags(varvt); - if (vt2->typeScope && vt2->typeScope->definedType) { - const_cast(parent->previous()->variable())->type(vt2->typeScope->definedType); - autoToken->type(vt2->typeScope->definedType); + Variable *var = const_cast(parent->previous()->variable()); + if (var) { + var->setFlags(varvt); + if (vt2->typeScope && vt2->typeScope->definedType) { + var->type(vt2->typeScope->definedType); + autoToken->type(vt2->typeScope->definedType); + } } } else if (vt2->container) { // TODO: Determine exact type of RHS diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f512f403b..a6cb3d49a 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -330,6 +330,7 @@ private: TEST_CASE(auto6); // #7963 (segmentation fault) TEST_CASE(auto7); TEST_CASE(auto8); + TEST_CASE(auto9); // #8044 (segmentation fault) } void array() { @@ -5159,6 +5160,31 @@ private: } } + void auto9() { // #8044 (segmentation fault) + GET_SYMBOL_DB("class DHTTokenTracker {\n" + " static const size_t SECRET_SIZE = 4;\n" + " unsigned char secret_[2][SECRET_SIZE];\n" + " void validateToken();\n" + "};\n" + "template struct DerefEqual derefEqual(const T& t) {\n" + " return DerefEqual(t);\n" + "}\n" + "template \n" + "struct RefLess {\n" + " bool operator()(const std::shared_ptr& lhs,\n" + " const std::shared_ptr& rhs)\n" + " {\n" + " return lhs.get() < rhs.get();\n" + " }\n" + "};\n" + "void DHTTokenTracker::validateToken()\n" + "{\n" + " for (auto& elem : secret_) {\n" + " }\n" + "}"); + ASSERT_EQUALS(true, db != nullptr); // not null + } + }; REGISTER_TEST(TestSymbolDatabase)