Bug 20732 – swap doesn't support types with impure gc or throwing copy constructors
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-13T14:15:50Z
Last change time
2020-04-13T17:49:37Z
Keywords
pull
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2020-04-13T14:15:50Z
struct S
{
this(ref const S other) {}
}
void main()
{
import std.alglorithm;
S s;
swap(s, s);
}
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/mutation.d(2824): Error: pure function std.algorithm.mutation.swap!(S).swap cannot call impure copy constructor onlineapp.S.this
The offending line is here:
https://github.com/dlang/phobos/blob/c4f9c18ca788cf4bdb57344681f302d8f1309f36/std/algorithm/mutation.d#L2824
swap works around elaborate assignment but not elaborate construction.
Comment #1 by dlang-bot — 2020-04-13T15:37:53Z
@schveiguy created dlang/phobos pull request #7442 "Fix issue 20732. Do not invoke any complex copy construction for swap" fixing this issue:
- Fix issue 20732. Do not invoke any complex copy construction for
std.algorithm.mutation.swap for the temporary.
https://github.com/dlang/phobos/pull/7442
Comment #2 by dlang-bot — 2020-04-13T17:49:37Z
dlang/phobos pull request #7442 "Fix issue 20732. Do not invoke any complex copy construction for swap" was merged into master:
- 637ba8560e94dbbbbbed821c455a47fe6d71d280 by Steven Schveighoffer:
Fix issue 20732. Do not invoke any complex copy construction for
std.algorithm.mutation.swap for the temporary.
https://github.com/dlang/phobos/pull/7442