Bug 5121 – Make std.algorithm.swap weakly pure

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-26T12:57:00Z
Last change time
2011-07-14T21:26:57Z
Keywords
patch
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-10-26T12:57:01Z
This is a test program that fails with dmd 2.050alpha: import std.algorithm: swap; pure int foo(int x, int y) { swap(x, y); return y; } void main() { assert(foo(10, 20) == 10); } But swap may be modified to become weakly pure, just changing this line 1063: void swap(T)(ref T a, ref T b) if (!is(typeof(T.init.proxySwap(T.init)))) Into: pure void swap(T)(ref T a, ref T b) if (!is(typeof(T.init.proxySwap(T.init)))) (Probably several other functions in Phobos may now be tagged was (weakly) pure.)
Comment #1 by bearophile_hugs — 2010-11-19T10:05:01Z
Comment #2 by yebblies — 2011-07-14T21:26:57Z
This code now compiles with the new purity inference in dmd 2.054 (or was it the phobos changes?) Either way, fixed.