Fixed #2428 (false alarm with code containing a throw clause)

This commit is contained in:
Daniel Marjamäki 2011-01-07 20:45:33 +01:00
parent 989e0e7ccb
commit 14cbaebfe2
2 changed files with 15 additions and 3 deletions

View File

@ -106,7 +106,7 @@ void CheckExceptionSafety::deallocThrow()
bool globalVar = false;
for (const Token *tok2 = _tokenizer->tokens(); tok2; tok2 = tok2->next())
{
if (tok->varId() == varid)
if (tok2->varId() == varid)
{
globalVar = true;
break;

View File

@ -35,7 +35,8 @@ private:
void run()
{
TEST_CASE(destructors);
TEST_CASE(deallocThrow);
TEST_CASE(deallocThrow1);
TEST_CASE(deallocThrow2);
}
void check(const std::string &code)
@ -66,7 +67,7 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", errout.str());
}
void deallocThrow()
void deallocThrow1()
{
check("int * p;\n"
"void f(int x)\n"
@ -78,6 +79,17 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Throwing exception in invalid state, p points at deallocated memory\n", errout.str());
}
void deallocThrow2()
{
check("void f() {\n"
" int* p = 0;\n"
" delete p;\n"
" throw 1;\n"
" p = new int;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestExceptionSafety)