diff --git a/lib/astutils.cpp b/lib/astutils.cpp index abff90f7b..b1542902b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1170,6 +1170,11 @@ bool FwdAnalysis::isGlobalData(const Token *expr) const bool globalData = false; visitAstNodes(expr, [&](const Token *tok) { + if (tok->varId() && !tok->variable()) { + // Bailout, this is probably global + globalData = true; + return ChildrenToVisit::none; + } if (tok->originalName() == "->") { // TODO check if pointer points at local data globalData = true; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 62b91f0fd..ae9ec8107 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -4294,6 +4294,14 @@ private: "}" ); ASSERT_EQUALS("", errout.str()); + + // Unknown variable + functionVariableUsage( + "void A::b(Date& result) {" + " result = 12;\n" + "}" + ); + ASSERT_EQUALS("", errout.str()); } };