From d8793c0db1eb7e981429f2bb06b45ebb023820da Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sat, 9 Jun 2018 14:14:37 -0700 Subject: [PATCH] fix Issue 18963 - Relax restrictions on 'return' parameters when parameter is not a pointer --- src/dmd/typesem.d | 6 ++---- test/fail_compilation/test16228.d | 14 +++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/dmd/typesem.d b/src/dmd/typesem.d index f1cabbf8a899..812e63570943 100644 --- a/src/dmd/typesem.d +++ b/src/dmd/typesem.d @@ -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; } } @@ -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 } } } diff --git a/test/fail_compilation/test16228.d b/test/fail_compilation/test16228.d index bec1f469913d..e8d6588e7eed 100644 --- a/test/fail_compilation/test16228.d +++ b/test/fail_compilation/test16228.d @@ -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 ) @@ -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); +} +