[Issue 24793] Allow implicit conversion of const pointers to void*

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 21 18:36:07 UTC 2024


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

Nick Treleaven <nick at geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick at geany.org

--- Comment #6 from Nick Treleaven <nick at geany.org> ---
comment 4:
> we're risking memory safety issues with stuff like this with the introduction of language features such as placement new.

Surely passing a `void*` to placement new is not going to be @safe anyway.

comment 5:
> Unless that function checks the validity of `p` at runtime, that's not a safe interface

True. But there is value in @system code of const(void*) not converting to
void* - that is useful with some C APIs. GLib uses const void* parameters
(aliased as gconstpointer) here:
https://docs.gtk.org/glib/callback.CompareFunc.html.

So perhaps explicit casting of a const T* to a void* should be @safe, because
safe D can't mutate the pointee byte(s). But I don't think it should be
implicitly allowed.

--


More information about the Digitalmars-d-bugs mailing list