Unreachable statement, do or do not, there is no try

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 9 11:00:14 PST 2015


DMD accept both :
int foo() {
   try {
     throw new Exception("blah");
   } catch(Exception e) {
     return 25;
   }
}

and

int foo() {
   try {
     throw new Exception("blah");
   } catch(Exception e) {
     return 25;
   }

   return 42;
}

Which is it ? What are the rule for the unreachable statment ? It 
seems that DMD is capable of figuring out that the try never 
returns, or it would complain about missing return in the first 
case. But that do not seems consistent with not triggering the 
unreachable statement in case 2.

I'm working on improving control flow analysis in SDC. My 
handling of try will error on case 2. Is that the right thing ?

Also, if it is possible to detect that a statement finishes, 
without triggering a unreachable statement error, is that 
possible to make it so for static ifs ?


More information about the Digitalmars-d mailing list