From f783d975a28febea3a323bae3ce5f902cec17aa9 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Sun, 16 Oct 2016 01:36:27 +0200 Subject: [PATCH] fix Issue 16582 - ParameterDefaults fails w/ scope parameter - workaround scope escape error to get default parameter - would require a working `return scope` for a proper implementation --- std/traits.d | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/std/traits.d b/std/traits.d index 8a9d35b90..2b779e0f5 100644 --- a/std/traits.d +++ b/std/traits.d @@ -1207,10 +1207,21 @@ template ParameterDefaults(func...) template Get(size_t i) { enum ParamName = ParameterIdentifierTuple!(func[0])[i]; + // workaround scope escape check, see + // https://issues.dlang.org/show_bug.cgi?id=16582 + // should use return scope once available static if (ParamName.length) - enum get = (PT[i..i+1]) => mixin(ParamName); + enum get = (PT[i..i+1]) @trusted + { + PT[i]* __pd_val = &mixin(ParamName); // workaround Bugzilla 16582 + return *__pd_val; + }; else // Unnamed parameter - enum get = (PT[i..i+1] __args) => __args[0]; + enum get = (PT[i..i+1] __args) @trusted + { + PT[i]* val = &__args[0]; // workaround Bugzilla 16582 + return *val; + }; static if (is(typeof(get()))) enum Get = get(); else @@ -1288,9 +1299,11 @@ alias ParameterDefaultValueTuple = ParameterDefaults; static immutable Colour white = Colour(255,255,255,255); } - void bug8106(Colour c = Colour.white){} + void bug8106(Colour c = Colour.white) {} //pragma(msg, PDVT!bug8106); static assert(PDVT!bug8106[0] == Colour.white); + void bug16582(scope int* val = null) {} + static assert(PDVT!bug16582[0] is null); }