From 4ef7839d6a10021aec99c2f0a9fc238ce9f7bed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 6 Dec 2008 16:34:44 +0000 Subject: [PATCH] Unreachable code : Fixed false positives for label --- CheckOther.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CheckOther.cpp b/CheckOther.cpp index b36eb1265..98153e86e 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -800,12 +800,15 @@ void CheckOther::unreachableCode() const TOKEN *tok = TOKEN::findmatch( _tokenizer->tokens(), "[;{}] return" ); while ( tok ) { + // Goto the 'return' token + tok = tok->next; + // Locate the end of the 'return' statement while ( tok && ! TOKEN::Match(tok, ";") ) tok = tok->next; - // Next token should be either "case", "default" or "}" - if (tok && tok->next && !TOKEN::Match( tok, "; case|default|}")) + // If there is a statement below the return it is unreachable + if (!TOKEN::Match(tok, "; case|default|}") && !TOKEN::Match(tok, "; %var% :")) { std::ostringstream errmsg; errmsg << _tokenizer->fileLine(tok->next) << ": Unreachable code below a 'return'";