From 93be440f92e537d229294c1f5e6a9a0fd42a6e02 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 3 Sep 2018 12:54:14 -0500 Subject: [PATCH] Fix issue 8709: crash with switch statement with followVar (#1362) * Fix crash with switch statement * Update comment --- lib/astutils.cpp | 3 +++ test/testother.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 03bd48a9a..e6019bce4 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -206,6 +206,9 @@ static const Token * followVariableExpression(const Token * tok, bool cpp) if (const Variable * var2 = tok2->variable()) { if(!var2->scope()) return tok; + // FIXME This is a quick fix. Fix SymbolDatabase so typeStartToken points at the variable declaration and not a case statement + if(Token::simpleMatch(var2->typeStartToken(), "case")) + return tok; const Token * endToken2 = var2->scope() != tok->scope() ? var2->scope()->bodyEnd : endToken; if (!var2->isLocal() && !var2->isConst() && !var2->isArgument()) return tok; diff --git a/test/testother.cpp b/test/testother.cpp index 43b7a9455..8f7398f5a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4576,6 +4576,16 @@ private: " int32_t c = int32_t(a / b);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // Issue #8709 + check("a b;\n" + "void c() {\n" + " switch (d) { case b:; }\n" + " double e(b);\n" + " if(e <= 0) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void checkSignOfUnsignedVariable() {