Skip to content

Commit

Permalink
fix Issue 18963 - Relax restrictions on 'return' parameters when para…
Browse files Browse the repository at this point in the history
…meter is not a pointer
  • Loading branch information
WalterBright committed Jun 9, 2018
1 parent 6a21060 commit d8793c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ private extern (C++) final class TypeSemanticVisitor : Visitor

if (tf.isreturn && !tf.isref && !tf.next.hasPointers())
{
mtype.error(loc, "function type `%s` has `return` but does not return any indirections", tf.toChars());
tf.isreturn = false;
}
}

Expand Down Expand Up @@ -964,9 +964,7 @@ private extern (C++) final class TypeSemanticVisitor : Visitor
}
else if (tf.next && !tf.next.hasPointers())
{
mtype.error(loc, "parameter `%s` is `return` but function does not return any indirections",
fparam.ident ? fparam.ident.toChars() : "");
errors = true;
fparam.storageClass &= ~STC.return_; // https://issues.dlang.org/show_bug.cgi?id=18963
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion test/fail_compilation/test16228.d
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* REQUIRED_ARGS: -dip25
TEST_OUTPUT:
---
fail_compilation/test16228.d(22): Error: function type `int() return` has `return` but does not return any indirections
fail_compilation/test16228.d(23): Error: function `test16228.S.bar` `static` member has no `this` to which `return` can apply
---
*/




// https://issues.dlang.org/show_bug.cgi?id=16228

int* wrap ( return ref int input )
Expand All @@ -22,3 +22,15 @@ struct S
int foo() return { return 3; }
static ref int bar() return { return x; }
}


// https://issues.dlang.org/show_bug.cgi?id=18963

T Identity(T)(return T t) { return t; }

void bar(int i, void* p)
{
Identity(p);
Identity(i);
}

0 comments on commit d8793c0

Please sign in to comment.