static if else behavior and is type comparison

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 11 04:10:53 PST 2016


On 03/11/16 09:21, Ali Çehreli via Digitalmars-d-learn wrote:
> You've been bitten by a common usability issue. :)
> 
> On 03/11/2016 12:02 AM, Fynn Schröder wrote:
>>      static if (is(U == ubyte)) {

>>      } else if (is(U == ushort)) {
> 
> You mean 'else static if'. (Not your fault: I (and others) wish the compiler warned about this problem.)

It can not warn about this "problem" - because it's a perfectly
fine and relatively common construct (a RT check guarded by a CT
check).
The problem comes from the static-if pseudo-keyword hack --
"static if" is effectively a keyword; if the syntax was eg "#if"
then such mistakes would be less likely. Obviously, it's a bit late
for such language change. One thing that the compiler could warn
about is: a RT-if that depends only on the result of an is-expression;
that would have caught the case above and rarely be wrong (with an
easy way to make the compiler happy). It would still miss more
complex cases, but those can't be warned about as they can occur
legitimately in generic code.

artur


More information about the Digitalmars-d-learn mailing list