From b5e064e737e4caf9c8f1fdc6f0c75f4979386133 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 1 Sep 2014 11:10:42 +0200 Subject: [PATCH] Fixed unreachableCode message if a lambda is returned (#6008). --- lib/checkother.cpp | 2 +- test/testother.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ba94c39a0..3099e92f8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1120,7 +1120,7 @@ void CheckOther::checkUnreachableCode() else if (Token::Match(tok, "[;{}:] return|throw")) { tok = tok->next(); // tok should point to return or throw for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { - if (tok2->str() == "(") + if (tok2->str() == "(" || tok2->str() == "{") tok2 = tok2->link(); if (tok2->str() == ";") { secondBreak = tok2->next(); diff --git a/test/testother.cpp b/test/testother.cpp index e6e4bf588..c22bc4a48 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2974,6 +2974,15 @@ private: " }));\n" "}", 0, false, false, false, false); ASSERT_EQUALS("", errout.str()); + + // #6008 + check("static std::function< int ( int, int ) > GetFunctor() {\n" + " return [](int a_, int b_) -> int {\n" + " int sum = a_ + b_;\n" + " return sum;\n" + " };\n" + "}", 0, false, false, false, false); + ASSERT_EQUALS("", errout.str()); }