diff --git a/lib/token.cpp b/lib/token.cpp index e324420f7..a7e96c90e 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1420,6 +1420,8 @@ const Token *Token::getValueTokenDeadPointer() const const Variable * const var = vartok->variable(); if (var->isStatic() || var->isReference()) continue; + if (var->scope()->type == Scope::eUnion && var->scope()->nestedIn == this->scope()) + continue; // variable must be in same function (not in subfunction) if (functionscope != getfunctionscope(var->scope())) continue; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index e3759715c..5ed37fd4c 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3912,6 +3912,17 @@ private: " dosth();\n" "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Dead pointer usage. Pointer 'former_hover' is dead if it has been assigned '&item' at line 5.\n", errout.str()); + + // #6575 + checkDeadPointer("void trp_deliver_signal() {\n" + " union {\n" + " Uint32 theData[25];\n" + " EventReport repData;\n" + " };\n" + " EventReport * rep = &repData;\n" + " rep->setEventType(NDB_LE_Connected);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };