Thread overview
[Issue 19783] Fail to emplace struct with betterC
Mar 31, 2019
Ulrich Küttler
Dec 22, 2020
Tomáš Chaloupka
Dec 23, 2020
Tomáš Chaloupka
Dec 23, 2020
Tomáš Chaloupka
Apr 27, 2021
Dlang Bot
Apr 29, 2021
Dlang Bot
March 31, 2019
https://issues.dlang.org/show_bug.cgi?id=19783

Ulrich Küttler <kuettler@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|phobos                      |dmd

--
December 22, 2020
https://issues.dlang.org/show_bug.cgi?id=19783

Tomáš Chaloupka <chalucha@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |betterC
                 CC|                            |chalucha@gmail.com

--
December 23, 2020
https://issues.dlang.org/show_bug.cgi?id=19783

--- Comment #1 from Tomáš Chaloupka <chalucha@gmail.com> ---
Similar problem when using core.lifetime:

```D
import core.lifetime;
import core.stdc.stdlib;

struct Foo { int bar; }

extern(C) void main()
{
        auto pf = malloc(Foo.sizeof)[0..Foo.sizeof].emplace!Foo(42);
        assert(pf.bar == 42);
}
```

With: dmd -g -debug -betterC -ofbc bc.d

Leads to:
/usr/bin/ld: bc.o: in function
`_D4core8lifetime__T7emplaceTS2bc3FooTiZQuFNaNbNiAviZPQz':
/home/tomas/dlang/dmd-2.094.2/linux/bin64/../../src/druntime/import/core/lifetime.d:284:
undefined reference to `_D4core8lifetime16testEmplaceChunkFNaNbNiNfAvmmZv'

--
December 23, 2020
https://issues.dlang.org/show_bug.cgi?id=19783

--- Comment #2 from Tomáš Chaloupka <chalucha@gmail.com> ---
For the record, this works (uses different template):

auto pf = (cast(Foo*)malloc(Foo.sizeof)).emplace!Foo(42);

--
April 27, 2021
https://issues.dlang.org/show_bug.cgi?id=19783

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@MoonlightSentinel created dlang/druntime pull request #3454 "Fix 19783 - Fail to emplace struct with betterC" fixing this issue:

- Fix 19783 - Fail to emplace struct with betterC

  Defining the helper function as a template ensures that it is available
  when not linking druntime.

  (`pragma(inline, true)` didn't work)

https://github.com/dlang/druntime/pull/3454

--
April 29, 2021
https://issues.dlang.org/show_bug.cgi?id=19783

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/druntime pull request #3454 "Fix 19783 - Fail to emplace struct with betterC" was merged into master:

- 41df5db46f613b5f538d51d53441fcfbe2760aab by MoonlightSentinel:
  Fix 19783 - Fail to emplace struct with betterC

  Defining the helper function as a template ensures that it is available
  when not linking druntime.

  (`pragma(inline, true)` didn't work)

https://github.com/dlang/druntime/pull/3454

--