diff --git a/src/statement.c b/src/statement.c index 60949f3746e0..ba316ef6b6d6 100644 --- a/src/statement.c +++ b/src/statement.c @@ -3882,7 +3882,7 @@ Statement *ReturnStatement::semantic(Scope *sc) } else { - if (tf->isref) + if (tf->isref && (fd->storage_class & STCauto)) { /* Determine "refness" of function return: * if it's an lvalue, return by ref, else return by value */ @@ -3895,11 +3895,11 @@ Statement *ReturnStatement::semantic(Scope *sc) unsigned errors = global.startGagging(); exp->checkEscapeRef(); if (global.endGagging(errors)) - { tf->isref = FALSE; // return by value - } + tf->isref = FALSE; // return by value } else tf->isref = FALSE; // return by value + fd->storage_class &= ~STCauto; } tf->next = exp->type; //fd->type = tf->semantic(loc, sc); // Removed with 6902 diff --git a/test/runnable/declaration.d b/test/runnable/declaration.d index 2c7b5275980a..58c111609b79 100644 --- a/test/runnable/declaration.d +++ b/test/runnable/declaration.d @@ -20,6 +20,34 @@ void test6475() static assert(is(X2 == int)); } +/***************************************************/ +// 6905 + +void test6905() +{ + auto foo1() { static int n; return n; } + auto foo2() { int n; return n; } + auto foo3() { return 1; } + static assert(typeof(&foo1).stringof == "int delegate()"); + static assert(typeof(&foo2).stringof == "int delegate()"); + static assert(typeof(&foo3).stringof == "int delegate()"); + + ref bar1() { static int n; return n; } + static assert(!__traits(compiles, { + ref bar2() { int n; return n; } + })); + static assert(!__traits(compiles, { + ref bar3() { return 1; } + })); + + auto ref baz1() { static int n; return n; } + auto ref baz2() { int n; return n; } + auto ref baz3() { return 1; } + static assert(typeof(&baz1).stringof == "int delegate() ref"); + static assert(typeof(&baz2).stringof == "int delegate()"); + static assert(typeof(&baz3).stringof == "int delegate()"); +} + /***************************************************/ // 7019 @@ -169,6 +197,7 @@ void test8942() int main() { test6475(); + test6905(); test7019(); test7239(); test8123();