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()); }