Bug 8978 – Constructor is called instead of implicit cast when initializing from expression tuple

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-08T05:26:34Z
Last change time
2024-12-13T18:02:26Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#18487 →

Comments

Comment #0 by verylonglogin.reg — 2012-11-08T05:26:34Z
The second `static assert` fails as `this(const S)` is called: --- template expressionTuple(expressions...) { alias expressions expressionTuple; } struct S { int* p; this(const S) { } } void main() { const S cs; static assert(!__traits(compiles, { S s = cs; })); // ok, cast is invalid alias expressionTuple!(cs) args; static assert(!__traits(compiles, { S s = args; })); // fails } --- Another example: --- template expressionTuple(expressions...) { alias expressions expressionTuple; } struct S { int i; this(S) { assert(0); } } void main() { alias expressionTuple!(S()) args; S s = args; // `assert(0);` is triggered } --- Workaround: --- alias expressionTuple!(...) args; static if(args.length == 1) S s = args[0]; else S s = args; ---
Comment #1 by verylonglogin.reg — 2012-11-08T05:49:42Z
It also affects templates with tuple parameter: --- template expressionTuple(expressions...) { alias expressions expressionTuple; } struct S { int* p; this(const S) { } } void main() { const S cs; static assert(!__traits(compiles, { S s = cs; })); // ok, cast is invalid void f(Args...)(Args args) { static assert(!__traits(compiles, { S s = args; })); // fails } f(cs); } ---
Comment #2 by robert.schadek — 2024-12-13T18:02:26Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18487 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB