From 4fb464982c80494a5be65b458d6b1d0e365520b8 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 22 Aug 2012 10:17:23 -0700 Subject: [PATCH] Fixed crash reported in #4076 --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 68a1230d1..35c1d52da 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -243,7 +243,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const bool retvalue = false; // is there such a function that returns a value? for (scope = symbolDatabase->scopeList.begin(); !retref && scope != symbolDatabase->scopeList.end(); ++scope) { - if (scope->type == Scope::eFunction && scope->function->type != Function::eConstructor && scope->function->type != Function::eCopyConstructor) { + if (scope->type == Scope::eFunction && scope->function && scope->function->type != Function::eConstructor && scope->function->type != Function::eCopyConstructor) { if (scope->className == funcname) { retref = scope->classDef->strAt(-1) == "&"; if (!retref) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 0b143c5a4..9a644b93f 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -557,6 +557,12 @@ private: " return foo();\n" "}"); ASSERT_EQUALS("", errout.str()); + + // Don't crash with function in unknown scope (#4076) + check("X& a::Bar() {}" + "X& foo() {" + " return Bar();" + "}"); } void returnReference3() {