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() {