[Issue 13010] Use variable range propagation (VRP) for static assert
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Tue Jul  1 01:44:33 PDT 2014
    
    
  
https://issues.dlang.org/show_bug.cgi?id=13010
--- Comment #6 from bearophile_hugs at eml.cc ---
(In reply to Kenji Hara from comment #4)
> By advancing the thought, compiler will be able to generate "statement is
> not reachable" warning in else branch of the code.
> 
> void test(ubyte n)
> {
>   immutable int i = n;
>   if (i >= 0)   // const-folding with VRP will optimize the condition to
> true.
>   { ... }
>   else
>   { ... }  // so the else branch could be determined to "not reachable"
> }
Such things could be a problem in templates, where the type is different in
different instantiations. This causes a warning if you instantiate it with an
T=uint:
void foo(T)(T n) {
    if (n >= 0) {
        /*...*/
    } else {
        /*...*/
    }
}
void main() {
    foo(1);  // OK
    foo(1u); // Causes a warning
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list