www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21720] New: Struct with destructor cannot be emplaced in


          Issue ID: 21720
           Summary: Struct with destructor cannot be emplaced in betterC
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: chalucha gmail.com

Reduced test case:

import core.stdc.stdlib : malloc;
import core.lifetime : emplace;

struct Foo {
    size_t foo;
    ~this() { } // works with this line commented out

void main() {
    auto p = malloc(Foo.sizeof);
    Foo* pay = emplace!Foo(p[0..Foo.sizeof], 1);


dmd -betterC test.d

Error: Cannot use try-catch statements with -betterC
Error: template instance `core.internal.lifetime.emplaceRef!(Foo, Foo,
int).emplaceRef.S.__ctor!()` error instantiating
       instantiated from here: `emplaceRef!(Foo, Foo, int)`
test.d(13):        instantiated from here: `emplace!(Foo, int)`

This worked with previous compilers.

Mar 15 2021