diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 52ce0ee35..bc1a3415a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1115,7 +1115,7 @@ void CheckOther::checkUnreachableCode() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { const Token* secondBreak = 0; const Token* labelName = 0; if (tok->link() && Token::Match(tok, "(|[|<")) diff --git a/test/testother.cpp b/test/testother.cpp index cbd352bd1..fdbbd7316 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2991,6 +2991,13 @@ private: " per_state_info() : enter(0), exit(0), events(0) {}\n" "};", 0, false, false, false, false); ASSERT_EQUALS("", errout.str()); + + // Garbage code - don't crash + check("namespace pr16989 {\n" + " class C {\n" + " C tpl_mem(T *) { return }\n" + " };\n" + "}"); }