Placement new and @trusted

Dennis dkorpel at gmail.com
Thu Sep 11 11:47:40 UTC 2025


On Wednesday, 10 September 2025 at 12:29:24 UTC, IchorDev wrote:
> If anyone has any ideas, please let me know.

The trick that's used in druntime is putting the part that still 
needs to be checked for attributes inside an `if (false)` block, 
for example:

https://github.com/dlang/dmd/blob/c81714b9bc7626e1d235fb2d6279dc73d47c9174/druntime/src/core/lifetime.d#L1981

```D
private T moveImpl(T)(return scope ref T source)
{
     // Properly infer safety from moveEmplaceImpl as the 
implementation below
     // might void-initialize pointers in result and hence needs 
to be @trusted
     if (false) moveEmplaceImpl(source, source);

     return trustedMoveImpl(source);
}
```

Other example:

https://github.com/dlang/dmd/blob/c81714b9bc7626e1d235fb2d6279dc73d47c9174/druntime/src/core/internal/newaa.d#L692



More information about the Digitalmars-d-learn mailing list