Fixed crash reported in #4076

This commit is contained in:
PKEuS 2012-08-22 10:17:23 -07:00
parent f238f3fad5
commit 4fb464982c
2 changed files with 7 additions and 1 deletions

View File

@ -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) {

View File

@ -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() {