diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0b27eac60..ea824ace0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1019,6 +1019,8 @@ void CheckOther::checkUnreachableCode() else if (Token::Match(tok, "break|continue ;")) secondBreak = tok->tokAt(2); else if (Token::Match(tok, "[;{}:] return|throw")) { + if (Token::simpleMatch(tok->astParent(), "?")) + continue; tok = tok->next(); // tok should point to return or throw for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { if (tok2->str() == "(" || tok2->str() == "{") diff --git a/test/testother.cpp b/test/testother.cpp index 4cb1e3f06..e228113ff 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2754,6 +2754,13 @@ private: " bar();\n" "}", nullptr, false, false, false, &settings); ASSERT_EQUALS("", errout.str()); + + // #8261 + check("void foo() {\n" + " (beat < 100) ? (void)0 : throw(0);\n" + " bar();\n" + "}", nullptr, false, false, false, &settings); + ASSERT_EQUALS("", errout.str()); }