static if else behavior and is type comparison

Marc Schütz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 11 05:48:11 PST 2016


On Friday, 11 March 2016 at 12:10:53 UTC, Artur Skawina wrote:
> 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).

It can first deprecate and later disallow

     static if(...) ... else if(...) ...

It's always possible (and IMO preferable) to write the clearer

     static if(...) { ... } else { if(...) ... }

It already does this for similar error-prone cases, e.g.

     if(...) ;
     while(...) ;
     // Error: use '{ }' for an empty statement, not a ';'


More information about the Digitalmars-d-learn mailing list