Compiling with unknown class gives no error

Duarte xporg.roso at gmail.com
Mon Mar 17 15:20:10 PDT 2014


Hi fellow coders,

While fooling around, I came across something I can't explain. 
Hope you can bring some light to this matter.
Let's say I have the following class definition:

class A
{
     /*
         Some stuff here
     */

     // B is a class defined nowhere, it just doesn't exist!
     B opBinary(string op)(float f)
     {
         return B();
     }
};


Compiling this with dmd/ldc will procude no error whatsoever, not 
even a warning (with -w/-wi enabled). It will only trigger a 
compile error if the operator is called at some point.

How come? Obviously if the class does not exist the compiler 
shouldn't be able to determine the return value of the overloaded 
operator. Unless there is some magic going on behind the scenes...

Just out of curiosity really. I usually avoid returning types 
that do not exist :)

Cheers!


More information about the digitalmars-d-ldc mailing list