Bug 13781 – Tuple assign should be @nogc

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-26T21:18:00Z
Last change time
2015-02-18T03:40:49Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

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
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/052c50d3cb3194b8fdd61436967ab4dfc971a253 Fix Issue 13781 - Tuple assign should be @nogc https://github.com/D-Programming-Language/phobos/commit/de5d3392782c85e79e71e257b3ba607ccff852a5 Merge pull request #2800 from Poita/Issue13781 Fix Issue 13781 - Tuple assign should be @nogc
Comment #7 by github-bugzilla — 2015-02-18T03:40:49Z