From 4bf9ff26ea987abb35a9736b34691adbb7640574 Mon Sep 17 00:00:00 2001 From: Pete Johns Date: Mon, 4 Oct 2010 08:16:11 +1100 Subject: [PATCH] Fixed 2071 (false positive: object destroyed immediately (when using '= { ... }')) Simplified check within CheckOther::checkMisusedScopedObject() as a result. --- lib/checkother.cpp | 3 +-- test/testother.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 007a6f136..5523f7bad 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3893,9 +3893,8 @@ void CheckOther::checkMisusedScopedObject() if (withinFunction && Token::Match(tok, "[;{}] %var% (") + && Token::Match(tok->tokAt(2)->link(), ") ;") && isIdentifierObjectType(tok) - && !Token::Match(tok->tokAt(2)->link(), ") ( %var%") - && !Token::simpleMatch(tok->tokAt(2)->link(), ") .") ) { tok = tok->next(); diff --git a/test/testother.cpp b/test/testother.cpp index e92fed815..41774f2e0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -114,6 +114,7 @@ private: TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor); TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors); TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject); + TEST_CASE(trac2071); } void check(const char code[]) @@ -3155,6 +3156,19 @@ private: ); ASSERT_EQUALS("", errout.str()); } + + void trac2071() + { + check("void f() {\n" + " struct AB {\n" + " AB(int a) { }\n" + " };\n" + "\n" + " const AB ab[3] = { AB(0), AB(1), AB(2) };\n" + "}\n" + ); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestOther)