Bug 15604 – [REG2.070] std.array.array of structs with template opAssign and default initialised 'new'ed class member

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-25T12:34:00Z
Last change time
2017-07-05T15:13:22Z
Assigned to
nobody
Creator
john.loughran.colvin

Comments

Comment #0 by john.loughran.colvin — 2016-01-25T12:34:59Z
% cat test.d void foo() { import std.array; [A()].array; } struct A { void opAssign(T)(T v) {} Object o = new Object; } % dmd test.d /usr/local/Cellar/dmd/HEAD/include/d2/std/conv.d(3970): Error: cannot implicitly convert expression (S(A(Object()))) of type S to immutable(S) /usr/local/Cellar/dmd/HEAD/include/d2/std/conv.d(3934): Error: template instance std.conv.emplaceInitializer!(S) error instantiating /usr/local/Cellar/dmd/HEAD/include/d2/std/array.d(125): instantiated from here: emplaceRef!(A, A, A) arrayBug.d(4): instantiated from here: array!(A[]) /usr/local/Cellar/dmd/HEAD/include/d2/std/array.d(128): Error: forward reference to inferred return type of function call () => cast(E[])result() This regression was introduced by https://github.com/D-Programming-Language/phobos/pull/3805
Comment #1 by john.loughran.colvin — 2016-01-26T09:19:56Z
The problem comes from a deeper issue with static initialisers with indirections, which are just a nightmare. Nonetheless, here's the fix: https://github.com/D-Programming-Language/phobos/pull/3952
Comment #2 by code — 2016-01-29T20:34:53Z
As I pointed out in the GitHub issue, I'm not convinced that this is a regression. Isn't it just an accepts-invalid bug in the compiler that the struct declaration is considered valid in the first place? From looking at the codegen, I find it hard to imagine that the current behavior (a single implicitly-shared object instance) would be what the user would expect.
Comment #3 by john.loughran.colvin — 2016-01-30T09:46:00Z
(In reply to David Nadlinger from comment #2) > As I pointed out in the GitHub issue, I'm not convinced that this is a > regression. Isn't it just an accepts-invalid bug in the compiler that the > struct declaration is considered valid in the first place? > > From looking at the codegen, I find it hard to imagine that the current > behavior (a single implicitly-shared object instance) would be what the user > would expect. I agree and have since deleted all such things from the codebase I was working on. I also hit some weird linker errors with them that I was unable to minimise examples for, so good riddance. On the topic of static initialisers with mutable indirections, what about these: struct A { int[] arr = [1, 2, 3]; } or this: Object globalSingleton; struct B { Object o = globalSingleton; }
Comment #4 by dlang-bugzilla — 2017-07-05T15:13:22Z
(In reply to John Colvin from comment #3) > On the topic of static initialisers with mutable indirections, what about > these: I believe all of those are invalid and should not compile. I filed issue 17604 for this (even though it's probably a duplicate of another issue filed somewhere), so I think we can now close this one.