Skip to content

Commit 0dc4b75

Browse files
committed
Fixed crash on invalid code danmar#6080
1 parent 7f2be2f commit 0dc4b75

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkexceptionsafety.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void CheckExceptionSafety::deallocThrow()
9393
tok = tok->next();
9494
if (Token::simpleMatch(tok, "[ ]"))
9595
tok = tok->tokAt(2);
96-
if (!tok)
96+
if (!tok || tok == scope->classEnd)
9797
break;
9898
if (!Token::Match(tok, "%var% ;"))
9999
continue;

test/testexceptionsafety.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class TestExceptionSafety : public TestFixture {
4949
TEST_CASE(nothrowAttributeThrow);
5050
TEST_CASE(nothrowAttributeThrow2); // #5703
5151
TEST_CASE(nothrowDeclspecThrow);
52+
53+
TEST_CASE(garbage);
5254
}
5355

5456
void check(const char code[], bool inconclusive = false) {
@@ -411,6 +413,10 @@ class TestExceptionSafety : public TestFixture {
411413
check("const char *func() __attribute((nothrow)); void func1() { return 0; }\n");
412414
ASSERT_EQUALS("", errout.str());
413415
}
416+
417+
void garbage() {
418+
check("{ } A() { delete }"); // #6080
419+
}
414420
};
415421

416422
REGISTER_TEST(TestExceptionSafety)

0 commit comments

Comments
 (0)