diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index 1e72cf709c66..a44fb2877a95 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -3933,9 +3933,9 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te buf.writeByte(' '); } - void ignoreReturn(string str) + void dg(string str) { - if (str != "return") + if (str != "return" && str != "scope") { // don't write 'ref' for ctors if ((ident == Id.ctor) && str == "ref") @@ -3944,7 +3944,7 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te buf.writeByte(' '); } } - t.attributesApply(&ignoreReturn); + t.attributesApply(&dg); if (t.linkage > LINK.d && hgs.ddoc != 1 && !hgs.hdrgen) { @@ -3977,7 +3977,15 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te buf.writeByte(')'); } parametersToBuffer(t.parameterList, buf, hgs); - if (t.isreturn) + if (t.isreturnscope && !t.isreturninferred) + { + buf.writestring(" return scope"); + } + else if (t.isScopeQual && !t.isscopeinferred) + { + buf.writestring(" scope"); + } + if (t.isreturn && !t.isreturnscope && !t.isreturninferred) { buf.writestring(" return"); } diff --git a/compiler/test/compilable/extra-files/header1.d b/compiler/test/compilable/extra-files/header1.d index 93f05a50c31f..9756264fcc3e 100644 --- a/compiler/test/compilable/extra-files/header1.d +++ b/compiler/test/compilable/extra-files/header1.d @@ -575,12 +575,17 @@ struct SafeS return this; } - ref SafeS foo3() return scope + ref SafeS foo3() scope { static SafeS s; return s; } + ref SafeS foo4() scope return + { + return this; + } + int* p; } diff --git a/compiler/test/compilable/extra-files/header1.di b/compiler/test/compilable/extra-files/header1.di index 11186409ddf4..91422fed8ab4 100644 --- a/compiler/test/compilable/extra-files/header1.di +++ b/compiler/test/compilable/extra-files/header1.di @@ -517,8 +517,9 @@ struct SafeS @safe { ref SafeS foo() return; - scope SafeS foo2() return; - ref scope SafeS foo3() return; + SafeS foo2() return scope; + ref SafeS foo3() scope; + ref SafeS foo4() scope return; int* p; } } diff --git a/compiler/test/compilable/extra-files/header1i.di b/compiler/test/compilable/extra-files/header1i.di index 1be656fa88f4..a77f3cb0945c 100644 --- a/compiler/test/compilable/extra-files/header1i.di +++ b/compiler/test/compilable/extra-files/header1i.di @@ -653,15 +653,19 @@ struct SafeS { return this; } - scope SafeS foo2() return + SafeS foo2() return scope { return this; } - ref scope SafeS foo3() return + ref SafeS foo3() scope { static SafeS s; return s; } + ref SafeS foo4() scope return + { + return this; + } int* p; } } diff --git a/compiler/test/fail_compilation/retref2.d b/compiler/test/fail_compilation/retref2.d index aaa5b41e306c..ca64653efaec 100644 --- a/compiler/test/fail_compilation/retref2.d +++ b/compiler/test/fail_compilation/retref2.d @@ -2,7 +2,7 @@ TEST_OUTPUT: --- fail_compilation/retref2.d(18): Error: function `ref int retref2.D.foo(return ref int)` does not override any function, did you mean to override `ref int retref2.C.foo(ref int)`? -fail_compilation/retref2.d(19): Error: function `ref scope int retref2.D.bar() return` does not override any function, did you mean to override `ref int retref2.C.bar()`? +fail_compilation/retref2.d(19): Error: function `ref int retref2.D.bar() scope return` does not override any function, did you mean to override `ref int retref2.C.bar()`? --- */