Bug 14222 – emplace implicit dynamic to static array fails

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-24T18:55:37Z
Last change time
2024-12-01T16:23:49Z
Assigned to
No Owner
Creator
John Colvin
Moved to GitHub: phobos#9654 →

Comments

Comment #0 by john.loughran.colvin — 2015-02-24T18:55:37Z
struct S { this(int[3] a){} } unittest { auto s0 = S([1,2,3]); //OK import std.conv : emplace; auto s1 = emplace!S(&s0, [1,2,3]); //Error } std/conv.d(4067): Error: static assert "S cannot be emplaced from (int[])." std/conv.d(4132): instantiated from here: emplaceImpl!(int[]) emplaceTest.d(10): instantiated from here: emplace!(S, int[])
Comment #1 by snarwin+bugzilla — 2024-10-03T22:09:45Z
I'm pretty sure this is impossible. IFTI always infers parameter types from argument types, not the other way around. The best workaround is probably to use std.array.staticArray to convert the array literal to the correct type: --- struct S { this(int[3] a){} } unittest { auto s0 = S([1,2,3]); //OK import std.conv : emplace; import std.array : staticArray; auto s1 = emplace!S(&s0, staticArray([1,2,3])); //OK } ---
Comment #2 by robert.schadek — 2024-12-01T16:23:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9654 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB