opEquals @safe is ignored
    Luis 
    luis.panadero at gmail.com
       
    Sun May 24 08:57:28 UTC 2020
    
    
  
Lets take this example code (https://run.dlang.io/is/Vkpx9j) :
´´´D
import std;
void main()
{
}
class ExampleC
{
   int x;
   this (int x) @safe
   {
     this.x = x;
   }
   override bool opEquals(Object o) const @trusted
   {
     if (ExampleC rhs = cast(ExampleC)o) {
       return this.x == rhs.x;
     }
     return false;
   }
}
@safe unittest
{
     auto c = new ExampleC(1);
     assert(c != new ExampleC(23));
}
´´´
dmd ignores @trusted or @safe on opEquals, throwing this error :
onlineapp.d(27): Error: @safe function 
onlineapp.__unittest_L24_C7 cannot call @system function 
object.opEquals
An override @system or @trusted function can't be @safe, or I it 
a bug ?
Also, how will this be affected by DIP1028 ?
    
    
More information about the Digitalmars-d-learn
mailing list