Comment #0 by bearophile_hugs — 2014-11-26T21:18:43Z
void main() @nogc {
import std.typecons: Tuple;
alias T = Tuple!(string,"s");
T x;
x = T.init;
}
dmd 2.067alpha:
test.d(5,7): Error: @nogc function 'D main' cannot call non-@nogc function 'std.typecons.Tuple!(string, "s").Tuple.opAssign!(Tuple!(string, "s")).opAssign'
Comment #1 by peter.alexander.au — 2014-12-14T19:55:10Z
Adding @nogc to Tuple.opAssign gives:
Error: @nogc function 'std.typecons.Tuple!(string, "s").Tuple.opAssign!(Tuple!(string, "s")).opAssign' cannot call non-@nogc function 'std.algorithm.swap!(Tuple!string).swap'
Adding @nogc to swap makes the code compile.
Both are templates, so @nogc should be inferred. Marking this as a DMD bug.
Comment #2 by k.hara.pg — 2014-12-15T02:55:20Z
(In reply to Peter Alexander from comment #1)
> Adding @nogc to Tuple.opAssign gives:
>
> Error: @nogc function 'std.typecons.Tuple!(string,
> "s").Tuple.opAssign!(Tuple!(string, "s")).opAssign' cannot call non-@nogc
> function 'std.algorithm.swap!(Tuple!string).swap'
>
> Adding @nogc to swap makes the code compile.
>
> Both are templates, so @nogc should be inferred. Marking this as a DMD bug.
This is a little problem in Phobos code.
'swap' is used from the opAssign template function in Tuple, but swap checks (hasElaborateAssign!T || !isAssignable!T) and it would see the signature of T.opAssign. On mutual function calls, attributes are inferred as non-@nogc by default. It's a design so this is not a compiler bug.
The correct fix is to mark std.algorithm.swap function as @nogc.
Comment #3 by peter.alexander.au — 2014-12-15T10:12:08Z
Ah, I see. Thanks for the clarification Kenji Hara, and apologies for marking as a compiler bug. I'll make the fix tonight.
Comment #4 by peter.alexander.au — 2014-12-15T20:40:55Z
Comment #5 by bearophile_hugs — 2014-12-15T22:46:45Z
(In reply to Kenji Hara from comment #2)
> On mutual function calls, attributes are inferred as non-@nogc
> by default. It's a design so this is not a compiler bug.
Is somewhere explained why there is this limitation? Can it be improved/lifted?
Comment #6 by github-bugzilla — 2015-01-08T00:57:38Z