From ee585877067ae72d2a0fa3274655788fcb788166 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 26 Oct 2015 08:29:43 +0100 Subject: [PATCH] Fixed false positive unreachableCode when ternary operator is used (#6664) --- lib/checkother.cpp | 2 +- test/testother.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 34a8bdb41..98720b879 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1021,7 +1021,7 @@ void CheckOther::checkUnreachableCode() } else if (Token::Match(tok, "goto %any% ;")) { secondBreak = tok->tokAt(3); labelName = tok->next(); - } else if (Token::Match(tok, "%name% (") && _settings->library.isnoreturn(tok)) { + } else if (Token::Match(tok, "%name% (") && _settings->library.isnoreturn(tok) && !Token::Match(tok->next()->astParent(), "?|:")) { if ((!tok->function() || (tok->function()->token != tok && tok->function()->tokenDef != tok)) && tok->linkAt(1)->strAt(1) != "{") secondBreak = tok->linkAt(1)->tokAt(2); } diff --git a/test/testother.cpp b/test/testother.cpp index 752ea1e58..53995bbba 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3147,6 +3147,19 @@ private: " per_state_info() : enter(0), exit(0), events(0) {}\n" "};", nullptr, false, false, false); ASSERT_EQUALS("", errout.str()); + + // #6664 + check("void foo() {\n" + " (beat < 100) ? (void)0 : exit(0);\n" + " bar();\n" + "}", nullptr, false, false, false, &settings); + ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" + " (beat < 100) ? exit(0) : (void)0;\n" + " bar();\n" + "}", nullptr, false, false, false, &settings); + ASSERT_EQUALS("", errout.str()); }