From b69528eb80522accee2e464b525ab000aca86896 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 30 Jan 2015 19:29:37 +0100 Subject: [PATCH] Bailout in Token::getValueTokenDeadPointer() if reference is used (#6399) --- lib/token.cpp | 2 +- test/testuninitvar.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/token.cpp b/lib/token.cpp index a0d9e9108..cb85f6fc5 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1416,7 +1416,7 @@ const Token *Token::getValueTokenDeadPointer() const if (!vartok || !vartok->isName() || !vartok->variable()) continue; const Variable * const var = vartok->variable(); - if (var->isStatic()) + if (var->isStatic() || var->isReference()) continue; // variable must be in same function (not in subfunction) if (functionscope != getfunctionscope(var->scope())) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index eee29398f..fc3a10770 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3944,6 +3944,29 @@ private: " f(tmp);\n" "}"); ASSERT_EQUALS("", errout.str()); + + // Don't warn about references (#6399) + checkDeadPointer("void f() {\n" + " wxAuiToolBarItem* former_hover = NULL;\n" + " for (i = 0, count = m_items.GetCount(); i < count; ++i) {\n" + " wxAuiToolBarItem& item = m_items.Item(i);\n" + " former_hover = &item;\n" + " }\n" + " if (former_hover != pitem)\n" + " dosth();\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + checkDeadPointer("void f() {\n" + " wxAuiToolBarItem* former_hover = NULL;\n" + " for (i = 0, count = m_items.GetCount(); i < count; ++i) {\n" + " wxAuiToolBarItem item = m_items.Item(i);\n" + " former_hover = &item;\n" + " }\n" + " if (former_hover != pitem)\n" + " 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()); } void uninitvar_posix_types() {