diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 20111ba59..03bd48a9a 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -175,6 +175,8 @@ static const Token * followVariableExpression(const Token * tok, bool cpp) // Skip array access if (Token::simpleMatch(varTok, "[")) return tok; + if (var->isVolatile()) + return tok; if (!var->isLocal() && !var->isConst()) return tok; if (var->isStatic() && !var->isConst()) diff --git a/test/testother.cpp b/test/testother.cpp index 320a66fbf..43b7a9455 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4075,6 +4075,10 @@ private: " if(a == 1) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("volatile const int var = 42;\n" + "void f() { if(var == 42) {} }\n"); + ASSERT_EQUALS("", errout.str()); } void duplicateExpressionLoop() {