Skip to content

Commit

Permalink
Merge pull request #1401 from 9rnsr/fix6905
Browse files Browse the repository at this point in the history
Issue 6905 - ref acts as auto ref when return type is missing
  • Loading branch information
WalterBright committed Jan 9, 2013
2 parents 701a4cc + 2518851 commit f193abd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/statement.c
Expand Up @@ -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
*/
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/runnable/declaration.d
Expand Up @@ -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

Expand Down Expand Up @@ -169,6 +197,7 @@ void test8942()
int main()
{
test6475();
test6905();
test7019();
test7239();
test8123();
Expand Down

0 comments on commit f193abd

Please sign in to comment.