diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index dd7eff77d..c82c10902 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -78,6 +78,9 @@ void CheckStl::iterators() if (var->typeEndToken()->str() == "auto") { if (Token::Match(var->typeEndToken(), "auto %name% ; %name% = %var% . %name% ( )")) { const Token* containertok = var->typeEndToken()->tokAt(5); + if (!containertok->variable()) + continue; + const Library::Container* container = _settings->library.detectContainer(containertok->variable()->typeStartToken()); if (!container) continue; diff --git a/test/teststl.cpp b/test/teststl.cpp index ada8c9583..8c232793a 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -535,6 +535,14 @@ private: " auto b = x.first;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\n" + " if (auto *TD = dyn_cast(this)) {\n" + " auto From = TD->getInstantiatedFrom();\n" + " }\n" + " return nullptr;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void STLSize() {