From a5b044a6e298c8f8ac182a5304edd0ec5497701a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 20 Apr 2013 07:51:44 +0200 Subject: [PATCH] Fixed #4754 (False positive: Map literals trigger redundant code warning) --- lib/checkother.cpp | 4 ++-- test/testincompletestatement.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 58f984ddb..0a9840fa1 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2056,8 +2056,8 @@ void CheckOther::checkIncompleteStatement() else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), ",|: %var%") && Token::Match(tok->link(), "} [,{]")) tok = tok->link(); - // C++11 vector initialization - else if (Token::Match(tok,"> %var% {")) + // C++11 vector initialization / return { .. } + else if (Token::Match(tok,"> %var% {") || Token::Match(tok, "[;{}] return {")) tok = tok->linkAt(2); else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) { diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 848495406..1ba67a424 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -191,6 +191,15 @@ private: " return (struct s){0,0};\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #4754 + check("unordered_map foo() {\n" + " return {\n" + " {\"hi\", \"there\"},\n" + " {\"happy\", \"sad\"}\n" + " };\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void cast() {