From 866d198756384f3c6c502ca565dd5043aa248471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 21 Aug 2018 06:32:33 +0200 Subject: [PATCH] Fixed #8697 (noreturn output stream) --- lib/library.cpp | 8 ++++++++ test/testvalueflow.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/library.cpp b/lib/library.cpp index 3a853ed07..ccf325872 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -904,6 +904,14 @@ bool Library::isScopeNoReturn(const Token *end, std::string *unknownFunc) const if (unknownFunc) unknownFunc->clear(); + if (Token::Match(end->tokAt(-2), "!!{ ; }")) { + const Token *lastTop = end->tokAt(-2)->astTop(); + if (Token::simpleMatch(lastTop, "<<") && + Token::simpleMatch(lastTop->astOperand1(), "(") && + Token::Match(lastTop->astOperand1()->previous(), "%name% (")) + return isnoreturn(lastTop->astOperand1()->previous()); + } + if (!Token::simpleMatch(end->tokAt(-2), ") ; }")) return false; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 9afd51b11..92482c2ba 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3358,6 +3358,14 @@ private: " x.front();\n" // <- unknown container size "}"; ASSERT(tokenValues(code, "x . front").empty()); + + code = "void f(std::vector ints) {\n" // #8697 + " if (ints.empty())\n" + " abort() << 123;\n" + " ints[0] = 0;\n" + "}"; + ASSERT(tokenValues(code, "ints [").empty()); + } };