Bailout in Token::getValueTokenDeadPointer() if reference is used (#6399)

This commit is contained in:
PKEuS 2015-01-30 19:29:37 +01:00
parent 0d151b45b5
commit b69528eb80
2 changed files with 24 additions and 1 deletions

View File

@ -1416,7 +1416,7 @@ const Token *Token::getValueTokenDeadPointer() const
if (!vartok || !vartok->isName() || !vartok->variable()) if (!vartok || !vartok->isName() || !vartok->variable())
continue; continue;
const Variable * const var = vartok->variable(); const Variable * const var = vartok->variable();
if (var->isStatic()) if (var->isStatic() || var->isReference())
continue; continue;
// variable must be in same function (not in subfunction) // variable must be in same function (not in subfunction)
if (functionscope != getfunctionscope(var->scope())) if (functionscope != getfunctionscope(var->scope()))

View File

@ -3944,6 +3944,29 @@ private:
" f(tmp);\n" " f(tmp);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); 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() { void uninitvar_posix_types() {