June 24, 2014 [Issue 7019] implicit constructors are inconsistently allowed | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=7019 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #15 from Kenji Hara <k.hara.pg@gmail.com> --- Remained issue will be fixed by issue 8864. struct S { this(int) { } } S[2] a = [1,2]; // Converted to: [S(1), S(2)] (In reply to Denis Shelomovskij from comment #14) > static assert(!__traits(compiles, { S2 s2 = { 5 }; })); // fails > static assert(!__traits(compiles, { S2 s2 = { s: 5 }; })); // fails These are expected behavior. The target type of the argument '5' can be determined to S, so implicit constructor call is handled. -- |
June 24, 2014 [Issue 7019] implicit constructors are inconsistently allowed | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=7019 --- Comment #16 from Denis Shelomovskij <verylonglogin.reg@gmail.com> --- (In reply to Kenji Hara from comment #15) > (In reply to Denis Shelomovskij from comment #14) > > static assert(!__traits(compiles, { S2 s2 = { 5 }; })); // fails > > static assert(!__traits(compiles, { S2 s2 = { s: 5 }; })); // fails > > These are expected behavior. > The target type of the argument '5' can be determined to S, so implicit > constructor call is handled. How does `S2 s2 = { 5 }` differ from `f(5)` or `S2 s2 = S2(5)`? IMO the only clean rule is: "Implicit conversion exists iff target type is explicitly stated." What is wrong with this rule? What rules and why are preferred? -- |
Copyright © 1999-2021 by the D Language Foundation