Bug 15313 – std.conv.emplace cannot initialize const objects

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-10T12:26:00Z
Last change time
2016-01-03T14:14:57Z
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2015-11-10T12:26:52Z
Consider this code: struct Node { int payload; Node* next; uint refs; } void main() { import core.stdc.stdlib : malloc; void[] buf = malloc(Node.sizeof)[0 .. Node.sizeof]; import std.conv : emplace; const Node* n = emplace!(Node)(buf, 42, null, 10); } Essentially the attempt is to create a new const Node object in the specified buffer. The code should work, but fails to compile with an obscure error message.
Comment #1 by petar.p.kirov — 2015-11-10T21:16:55Z
Andrei, I think you meant to write: const Node* n = emplace!(const Node)(buf, 42, null, 10);
Comment #2 by andrei — 2015-11-10T22:21:46Z
(In reply to ZombineDev from comment #1) > Andrei, I think you meant to write: > const Node* n = emplace!(const Node)(buf, 42, null, 10); Correct, thanks! By mistake I pasted the minimally changed code that does work.
Comment #3 by andrei — 2015-11-11T05:13:43Z
Comment #4 by github-bugzilla — 2015-11-11T09:28:33Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/d48220ac65733ae8854ea73ebc56443b3d29f648 Fix Issue 15313 - std.conv.emplace cannot initialize const objects https://github.com/D-Programming-Language/phobos/commit/8e20ab5ac32aec2b0a86087f1fb5c4057f790f2d Merge pull request #3803 from andralex/emplace Issue 15313 - std.conv.emplace cannot initialize const objects
Comment #5 by github-bugzilla — 2016-01-03T14:14:57Z