June 18, 2010 [Issue 4342] New: branches that are known as not taken at compile time should not be checked | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4342 Summary: branches that are known as not taken at compile time should not be checked Product: D Version: D1 Platform: Other OS/Version: Mac OS X Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: fawzi@gmx.ch --- Comment #0 from Fawzi Mohamed <fawzi@gmx.ch> 2010-06-18 02:46:43 PDT --- I see the following code as valid, and thus the present bug as "rejects-valid" {{{ module bug; extern(C) int printf(char*,...); void f(S...)(S args){ if (args[0].length>1 && args[0][1]>='0' && args[0][1]<='9'){ printf("bla,%d\n",args[0][1]-'0'); } } void main(){ f("x"); } }}} while the check in the if is correctly ignored (as it is unreachable because the length of args[0] is 1) the body of the if still checks args[0][1] and finds that it is out of bounds and rejects it. with bug.d(6): Error: array index 1 is out of bounds _param_0[0 .. 1] -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 27, 2012 [Issue 4342] branches that are known as not taken at compile time should not be checked | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=4342 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug@yahoo.com.au Resolution| |INVALID --- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-09-27 00:33:34 PDT --- This if statement is a peculiar mix of compile-time and runtime conditions. It should be rewritten as: void f(S...)(S args) { static if (args[0].length>1) { if (args[0][1]>='0' && args[0][1]<='9') { printf("bla,%d\n",args[0][1]-'0'); } } } The enhancement is basically a request for syntax sugar in these situations: turn "if (false)" into "static if(false)". But it's very bug prone, eg this program would compile: ------ void main(int argc) { byte x = argc; if (x > 1000) { lets_confuse_the_maintenance_programmer() *= undefined_variable; } } ----- Will not be implemented. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation