Why is `opequals` for objects not `@safe` by default?

Liam McGillivray yoshi.pit.link.mario at gmail.com
Fri Apr 5 05:17:07 UTC 2024


I am rather new to D, and have just began using the `@safe` and 
`@nogc` attributes. I have just begun using FLUID, a GUI library 
that requires safe delegates to be passed to it's objects.

While writing in `@safe` mode has mostly been not very difficult, 
and I usually have a sense of why the compiler rejects what it 
rejects, I was quite surprised when the compiler rejected an 
`opEquals` between two class objects. This is the default 
`opEquals` function which from my understanding simply compares 
the two memory addresses.

I don't see why this would ever be considered unsafe, even if the 
class isn't marked as `@safe`. Is doing this operation with a 
`@safe` class really any more or less risky than doing it with a 
`@system` class?

Is this just an oversight, or was this a deliberate choice?


More information about the Digitalmars-d mailing list