From 14cbaebfe2bf898d43d20ecfebf90fbf0be08be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 7 Jan 2011 20:45:33 +0100 Subject: [PATCH] Fixed #2428 (false alarm with code containing a throw clause) --- lib/checkexceptionsafety.cpp | 2 +- test/testexceptionsafety.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index edee7221a..cdadcc66c 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -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; diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 52b93e1b2..9d05870c2 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -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)