Fixed #2428 (false alarm with code containing a throw clause)
This commit is contained in:
parent
989e0e7ccb
commit
14cbaebfe2
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue