Issue 24866 - Inconsistent behavior in safe checking of conversion to void
Summary: Inconsistent behavior in safe checking of conversion to void
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: safe
Depends on:
Blocks:
 
Reported: 2024-11-18 18:36 UTC by Walter Bright
Modified: 2024-11-18 19:00 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2024-11-18 18:36:48 UTC
```
@safe:

struct T { int* a,b,c; }

void bar(void[24]);
void gee(void*);

void test() {
    static T t;
    gee(&t);              // no error
    bar(cast(void[24])t); // cast from `T` to `void[24]` not allowed in safe code
}
```
Both should be allowed or both should error.
Comment 1 Richard (Rikki) Andrew Cattermole 2024-11-18 19:00:06 UTC
Due to placement new, I'm on the side of disallowing conversion to ``void*`` and ``void[]`` in ``@safe``.

We have been relying on a language feature like that not existing and it opens up a major can of worms to have it.

Related: https://issues.dlang.org/show_bug.cgi?id=24772