diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index dd59f682a..108e528d9 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2781,7 +2781,7 @@ namespace { if (var->declarationId() == loopVar->varId()) return false; const Scope* scope = var->scope(); - return scope->isNestedIn(bodyTok->scope()); + return scope && scope->isNestedIn(bodyTok->scope()); } private: diff --git a/test/teststl.cpp b/test/teststl.cpp index 9766c0d1a..7009e8e44 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -5476,6 +5476,23 @@ private: true); ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop.\n", errout.str()); + + check("class C {\n" + "private:\n" + " QString s;\n" + "public:\n" + " C(QString);\n" + "private slots:\n" + " void f() {\n" + " QVERIFY(QDir(s).exists());\n" + " }\n" + " void f(const QStringList& d) {\n" + " for (QString f : d)\n" + " QDir(s);\n" + " }\n" + "};\n", + true); + ASSERT_EQUALS("", errout.str()); } void invalidContainer() {