Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1401 from 9rnsr/fix6905

Issue 6905 - ref acts as auto ref when return type is missing
  • Loading branch information...
commit f193abd3a39759f432197ba9f37e48518fb4499a 2 parents 701a4cc + 2518851
Walter Bright WalterBright authored
Showing with 32 additions and 3 deletions.
  1. +3 −3 src/statement.c
  2. +29 −0 test/runnable/declaration.d
6 src/statement.c
View
@@ -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
29 test/runnable/declaration.d
View
@@ -21,6 +21,34 @@ void test6475()
}
/***************************************************/
+// 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
struct S7019
@@ -169,6 +197,7 @@ void test8942()
int main()
{
test6475();
+ test6905();
test7019();
test7239();
test8123();
Please sign in to comment.
Something went wrong with that request. Please try again.