Compiling with unknown class gives no error

bearophile bearophileHUGS at lycos.com
Mon Mar 17 15:43:59 PDT 2014


Duarte:

> 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.

Similar questions are better asked in D.learn.

opBinary is not a method, it's a method template. So until you 
instantiate it, it doesn't actually exist. For some reasons for 
templates like C++/D ones you can't perform a full analysis of 
un-instantiated templated code. Time ago some people have asked 
for a partial analysis of template code, but Andrei was against 
it.

Extra note: don't end D class definitions (and structs/enums) 
with a semicolon.

Bye,
bearophile


More information about the digitalmars-d-ldc mailing list