digitalmars.D - Should unreachable code be considered an error?
- Bernard Helyer (4/4) Aug 18 2011 I asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php?
- Bernard Helyer (2/2) Aug 18 2011 http://bit.ly/ojnbwj
- Stewart Gordon (4/6) Aug 19 2011 It's _your_ newsreader that had trouble with it - just viewed the source...
- Timon Gehr (18/22) Aug 18 2011 The trouble with making dead code an error in general is that the
- Bernard Helyer (5/9) Aug 18 2011 I'm talking about the unambiguous cases, the ones where a basic block ha...
- Timon Gehr (3/12) Aug 18 2011 I was half joking. Fact is, if assert(0); is not dead code, the program
- Stewart Gordon (10/14) Aug 19 2011 So essentially you're looking to catch cases where, if you consider the ...
- Bernard Helyer (4/9) Aug 19 2011 Pretty much, minor correction on the last part -- an arrow means that th...
- Stewart Gordon (6/15) Aug 22 2011 That's more or less what I meant. The compiler can't identify all arrow...
- Michel Fortin (29/48) Aug 24 2011 But what about templates? Take this pretty reasonable function template:
-
Stewart Gordon
(18/28)
Aug 29 2011
- Don (6/38) Aug 31 2011 What if range.empty is simply the compile-time constant 'false'?
- Stewart Gordon (14/19) Sep 18 2011 That's exactly the case I've just covered.
- Rory McGuire (7/28) Sep 20 2011 Perhaps a warning, there are to many ways to make "unreachable" code
-
Stewart Gordon
(6/8)
Oct 02 2011
- Walter Bright (12/14) Oct 02 2011 Consider:
- Gor Gyolchanyan (11/27) Oct 02 2011 Good point.
-
Stewart Gordon
(18/25)
Oct 11 2011
- Bernard Helyer (6/6) Aug 18 2011 Faramir on the Ars forums makes an excellent point:
- Bernard Helyer (6/6) Aug 18 2011 Faramir on the Ars forums makes an excellent point:
- Bernard Helyer (6/6) Aug 18 2011 Faramir on the Ars forums makes an excellent point:
- Bernard Helyer (6/6) Aug 18 2011 Faramir on the Ars forums makes an excellent point:
- Bernard Helyer (2/2) Aug 18 2011 Sigh. Sorry about that. The NG is being really flakey -- I only clicked
- Bernard Helyer (6/6) Aug 18 2011 Faramir on the Ars forums makes an excellent point:
- Robert Clipsham (7/13) Aug 18 2011 Definitely a warning, I get a lot of dead code during development -
- Timon Gehr (4/10) Aug 18 2011 You mean string mixins?
- Don (4/17) Aug 18 2011 Yes, the equivalent to the C preprocessor is version statements.
- maarten van damme (5/25) Aug 19 2011 Why not a warning but when compiling using the -release flag throw an er...
- Walter Bright (2/3) Aug 22 2011 Statically unreachable code is removed by the optimizer.
- Nick Sabalausky (7/11) Aug 18 2011 No. That would be a royal pain in the ass during debugging. I expect to ...
- Sean Kelly (9/22) Aug 19 2011 to be=20
- Don (12/28) Aug 21 2011 I have encountered bugs of the form:
- Sean Kelly (18/37) Aug 22 2011 Was this broken condition something that could have been detected static...
- Don (5/29) Aug 23 2011 Yes.
- Sean Kelly (8/17) Aug 24 2011 statically? I've encountered plenty of broken conditions, but I've =
I asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=20&t=1153378&p=21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the linked forum post for more details ).
Aug 18 2011
http://bit.ly/ojnbwj For those newsreaders that have trouble with the full link.
Aug 18 2011
On 18/08/2011 12:44, Bernard Helyer wrote:http://bit.ly/ojnbwj For those newsreaders that have trouble with the full link.It's _your_ newsreader that had trouble with it - just viewed the source and there is indeed a line break there. But thanks. Stewart.
Aug 19 2011
On 08/18/2011 01:37 PM, Bernard Helyer wrote:I asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=20&t=1153378&p=21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the linked forum post for more details ).The trouble with making dead code an error in general is that the compiler is not able to detect dead code in most cases. If it is considered an error, each instance of dead code that the compiler cannot detect could be considered an accepts-invalid bug. Also, since the compiler is allowed to assume that any assert(0); is dead code, assert(0) would always be a compile time error. =) if(__ctfe){ // dead code during runtime goes here }else{ // dead code during compile time goes here } But I think making goto label; statement; label: An error would imho be ok, if you think it is worth the deviation from the reference implementation.
Aug 18 2011
On Thu, 18 Aug 2011 14:14:08 +0200, Timon Gehr wrote:The trouble with making dead code an error in general is that the compiler is not able to detect dead code in most cases.I'm talking about the unambiguous cases, the ones where a basic block has no parents (i.e. there is no way to enter that code block).Also, since the compiler is allowed to assume that any assert(0); is dead code, assert(0) would always be a compile time error. =)No, only if statements followed the assert(0) (which marks the control flow block as terminated, just like return).
Aug 18 2011
On 08/18/2011 02:19 PM, Bernard Helyer wrote:On Thu, 18 Aug 2011 14:14:08 +0200, Timon Gehr wrote:I was half joking. Fact is, if assert(0); is not dead code, the program is in error.The trouble with making dead code an error in general is that the compiler is not able to detect dead code in most cases.I'm talking about the unambiguous cases, the ones where a basic block has no parents (i.e. there is no way to enter that code block).Also, since the compiler is allowed to assume that any assert(0); is dead code, assert(0) would always be a compile time error. =)No, only if statements followed the assert(0) (which marks the control flow block as terminated, just like return).
Aug 18 2011
On 18/08/2011 13:19, Bernard Helyer wrote: <snip>I'm talking about the unambiguous cases, the ones where a basic block has no parents (i.e. there is no way to enter that code block).So essentially you're looking to catch cases where, if you consider the function as a flow chart, there is no chain of arrows from the start of the function to the statement in question. That should be straightforward. But you're not worrying about catching cases where some arrow would never be followed. Have I got that right? <snip>No, only if statements followed the assert(0) (which marks the control flow block as terminated, just like return).Not sure whether it should be allowed to be used e.g. to prevent execution of code that is under construction. Stewart.
Aug 19 2011
On Sat, 20 Aug 2011 01:42:56 +0100, Stewart Gordon wrote:So essentially you're looking to catch cases where, if you consider the function as a flow chart, there is no chain of arrows from the start of the function to the statement in question. That should be straightforward. But you're not worrying about catching cases where some arrow would never be followed. Have I got that right?Pretty much, minor correction on the last part -- an arrow means that the compiler considers it a possibility, so it's not considered in so far as the data structure doesn't make the distinction.
Aug 19 2011
On 20/08/2011 07:28, Bernard Helyer wrote:On Sat, 20 Aug 2011 01:42:56 +0100, Stewart Gordon wrote:That's more or less what I meant. The compiler can't identify all arrows that will never be followed - this would mean solving the halting problem. So it takes the view that any arrow _may_ be followed. But if there's no arrow at all leading to a statement, the compiler can easily see that it's unreachable and so issue a warning/error. Stewart.So essentially you're looking to catch cases where, if you consider the function as a flow chart, there is no chain of arrows from the start of the function to the statement in question. That should be straightforward. But you're not worrying about catching cases where some arrow would never be followed. Have I got that right?Pretty much, minor correction on the last part -- an arrow means that the compiler considers it a possibility, so it's not considered in so far as the data structure doesn't make the distinction.
Aug 22 2011
On 2011-08-22 21:27:39 +0000, Stewart Gordon <smjg_1998 yahoo.com> said:On 20/08/2011 07:28, Bernard Helyer wrote:But what about templates? Take this pretty reasonable function template: bool frontEquals(R, V)(R range, V value) { if (range.empty) return false; else return range.front == value; } This will work fine with most ranges, but if you encounter an infinite range (with empty defined as "enum empty = false") then the "return false" statement becomes unreachable and you'll get an error/warning? It doesn't make sense. Or perhaps we should require the above to be written like this: bool frontEquals(R, V)(R range, V value) { static if (!range.isInifinite) if (range.empty) return false; return range.front == value; } But isn't that messy? And I'm dealing with only one possibility here… what if a range was always empty? Something else to care about. Thankfully I'm only checking a boolean property limited to two values. -- Michel Fortin michel.fortin michelf.com http://michelf.com/On Sat, 20 Aug 2011 01:42:56 +0100, Stewart Gordon wrote:That's more or less what I meant. The compiler can't identify all arrows that will never be followed - this would mean solving the halting problem. So it takes the view that any arrow _may_ be followed. But if there's no arrow at all leading to a statement, the compiler can easily see that it's unreachable and so issue a warning/error.So essentially you're looking to catch cases where, if you consider the function as a flow chart, there is no chain of arrows from the start of the function to the statement in question. That should be straightforward. But you're not worrying about catching cases where some arrow would never be followed. Have I got that right?Pretty much, minor correction on the last part -- an arrow means that the compiler considers it a possibility, so it's not considered in so far as the data structure doesn't make the distinction.
Aug 24 2011
On 25/08/2011 02:41, Michel Fortin wrote: <snip>bool frontEquals(R, V)(R range, V value) { if (range.empty) return false; else return range.front == value; } This will work fine with most ranges, but if you encounter an infinite range (with empty defined as "enum empty = false") then the "return false" statement becomes unreachable and you'll get an error/warning? It doesn't make sense.<snip> The structure of a flowchart is not affected by the values of variables, or even constants, in it. _____________ ( frontEquals ) ¯¯¯¯¯¯|¯¯¯¯¯¯ ______________ ______v______ ( return false )<--- true ---< range.empty > ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯|¯¯¯¯¯¯ false | ______________v______________ ( return range.front == value ) ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Replacing "range.empty" with "false" doesn't magically cause the true arrow to vanish. Stewart.
Aug 29 2011
On 29.08.2011 15:29, Stewart Gordon wrote:On 25/08/2011 02:41, Michel Fortin wrote: <snip>What if range.empty is simply the compile-time constant 'false'? Isn't: if (false) {...} unreachable code? If it doesn't create an error, what would?bool frontEquals(R, V)(R range, V value) { if (range.empty) return false; else return range.front == value; } This will work fine with most ranges, but if you encounter an infinite range (with empty defined as "enum empty = false") then the "return false" statement becomes unreachable and you'll get an error/warning? It doesn't make sense.<snip> The structure of a flowchart is not affected by the values of variables, or even constants, in it. _____________ ( frontEquals ) ¯¯¯¯¯¯|¯¯¯¯¯¯ ______________ ______v______ ( return false )<--- true ---< range.empty > ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯|¯¯¯¯¯¯ false | ______________v______________ ( return range.front == value ) ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Replacing "range.empty" with "false" doesn't magically cause the true arrow to vanish. Stewart.
Aug 31 2011
On 31/08/2011 09:56, Don wrote: <snip>What if range.empty is simply the compile-time constant 'false'?That's exactly the case I've just covered.Isn't: if (false) {...} unreachable code? If it doesn't create an error, what would?doSomething(); return; doSomethingElse(); including more complicated equivalents like if (condition) { return something; } else { return somethingElse; } doSomethingElse(); Stewart.
Sep 18 2011
Perhaps a warning, there are to many ways to make "unreachable" code reachable. In other words, it is surely too much work to implement currently. Plus I find it annoying in Java when that happens, because often I'm just quickly testing a different return. -Rory On Mon, Sep 19, 2011 at 2:06 AM, Stewart Gordon <smjg_1998 yahoo.com> wrote:On 31/08/2011 09:56, Don wrote: <snip>What if range.empty is simply the compile-time constant 'false'?That's exactly the case I've just covered. Isn't:if (false) {...} unreachable code? If it doesn't create an error, what would?doSomething(); return; doSomethingElse(); including more complicated equivalents like if (condition) { return something; } else { return somethingElse; } doSomethingElse(); Stewart.
Sep 20 2011
On 20/09/2011 09:17, Rory McGuire wrote:Perhaps a warning, there are to many ways to make "unreachable" code reachable. In other words, it is surely too much work to implement currently.<snip top of upside-down reply> If the compiler can optimise away code that will never run because no arrow in the flowchart leads to it, why can't it just as well generate an error on the same code? Simply because we can't rely on every compiler to perform even the most basic cases of DCE? Stewart.
Oct 02 2011
On 10/2/2011 2:18 PM, Stewart Gordon wrote:Simply because we can't rely on every compiler to perform even the most basic cases of DCE?Consider: if (a) { ... code ... } Sometimes, when debugging, I'll do: if (0 && a) { ... code ... } to temporarily disable it. Should that be made illegal? If so, what about: const X = 0; if (X && a) { ... code ... } Illegal too? What about: bool foo() { ... } if (foo() && a) { ... code ... } where foo() may be evaluatable at compile time. How far should this go?
Oct 02 2011
Good point. Dead branch isn't a problem IMO. In the worst case it's gonna make the binary a few bytes longer. It's not worth all the effort of trying to make the compiler complain about= it. Besides, it is often required to disable a branch for debugging purposes, although in those cases I'd rather use a more obvious solution, like version(none) or /+ +/. On Mon, Oct 3, 2011 at 1:41 AM, Walter Bright <newshound2 digitalmars.com> wrote:On 10/2/2011 2:18 PM, Stewart Gordon wrote::Simply because we can't rely on every compiler to perform even the most basic cases of DCE?Consider: =A0 if (a) { ... code ... } Sometimes, when debugging, I'll do: =A0 if (0 && a) { ... code ... } to temporarily disable it. Should that be made illegal? If so, what about==A0 const X =3D 0; =A0 if (X && a) { ... code ... } Illegal too? What about: =A0 bool foo() { ... } =A0 if (foo() && a) { ... code ... } where foo() may be evaluatable at compile time. How far should this go?
Oct 02 2011
On 02/10/2011 22:41, Walter Bright wrote:On 10/2/2011 2:18 PM, Stewart Gordon wrote:<snip> I was talking about cases of DCE that are even more basic than this, such as: void qwert() { return; yuiop(); } void asdfg() { if (hjkl) { return zxcvb; } else { return nm; } qaz(); } These are exactly what I mean by no arrow leading to a given statement. In your examples, OTOH, the arrow exists - it will just never be followed. Stewart.Simply because we can't rely on every compiler to perform even the most basic cases of DCE?Consider: if (a) { ... code ... } Sometimes, when debugging, I'll do: if (0 && a) { ... code ... }
Oct 11 2011
Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.
Aug 18 2011
Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.
Aug 18 2011
Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.
Aug 18 2011
Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.
Aug 18 2011
Sigh. Sorry about that. The NG is being really flakey -- I only clicked send once.
Aug 18 2011
Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.
Aug 18 2011
On 18/08/2011 13:38, Bernard Helyer wrote:Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.Definitely a warning, I get a lot of dead code during development - making it an error would be annoying, I only care about the dead code when it gets to release/commit time and I'm cleaning the code up. -- Robert http://octarineparrot.com/
Aug 18 2011
On 08/18/2011 02:38 PM, Bernard Helyer wrote:Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.You mean string mixins? As string mixins are so much more expressive than C macros, one should actually almost never get trivial dead code in well designed string mixins.
Aug 18 2011
Timon Gehr wrote:On 08/18/2011 02:38 PM, Bernard Helyer wrote:Yes, the equivalent to the C preprocessor is version statements. Obviously anything wrapped in a version(none) block shouldn't generate an "unreachable code" error...Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.You mean string mixins? As string mixins are so much more expressive than C macros, one should actually almost never get trivial dead code in well designed string mixins.
Aug 18 2011
Why not a warning but when compiling using the -release flag throw an error? Sounds logical to me as unreachable code can be there because of debugging,etc but any released executable should not contain unreachable code. 2011/8/18 Don <nospam nospam.com>Timon Gehr wrote:On 08/18/2011 02:38 PM, Bernard Helyer wrote:Yes, the equivalent to the C preprocessor is version statements. Obviously anything wrapped in a version(none) block shouldn't generate an "unreachable code" error...Faramir on the Ars forums makes an excellent point: "With the c preprocessor, both theoretically and as it is used in practice, you can easily get dead code in certain compile paths that is live in others." I think template mixins can achieve the same sort of shenanigans. I think warning it is.You mean string mixins? As string mixins are so much more expressive than C macros, one should actually almost never get trivial dead code in well designed string mixins.
Aug 19 2011
On 8/19/2011 8:30 AM, maarten van damme wrote:any released executable should not contain unreachable code.Statically unreachable code is removed by the optimizer.
Aug 22 2011
"Bernard Helyer" <b.helyer gmail.com> wrote in message news:j2ithq$12kd$1 digitalmars.com...I asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=20&t=1153378&p=21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the linked forum post for more details ).No. That would be a royal pain in the ass during debugging. I expect to be able to stick a "return xxxx;" anywhere I want to test something and not have the compiler crap out because I didn't deal with the overhead of commenting out the rest. A warning might be nice, though.
Aug 18 2011
On Aug 18, 2011, at 10:29 AM, Nick Sabalausky wrote:"Bernard Helyer" <b.helyer gmail.com> wrote in message=20 news:j2ithq$12kd$1 digitalmars.com...linkedI asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=3D20&t=3D1153378&p=3D21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the =to be=20forum post for more details ).=20 No. That would be a royal pain in the ass during debugging. I expect =able to stick a "return xxxx;" anywhere I want to test something and =not=20have the compiler crap out because I didn't deal with the overhead of=20=commenting out the rest. =20 A warning might be nice, though.A warning if anything. I've never encountered a situation where code = was made unreachable by accident. I also get "unreachable code" = warnings periodically, for code that is absolutely reachable. I don't = want my code to not compile simply because the compiler can't perform = adequate flow analysis.=
Aug 19 2011
Sean Kelly wrote:On Aug 18, 2011, at 10:29 AM, Nick Sabalausky wrote:I have encountered bugs of the form: if (cond) { /* unreachable */ } and the cond was unintentionally always false. The last time I encountered such a bug was last week. I'm surprised your experience is so different. It's crucial that it should never report "unreachable" if it is unsure (not even a warning). But I think conditional compilation is a huge problem -- code may be valid under different compilation conditions. I suspect that to eliminate all the false positives, it'd have to be so conservative, that it wouldn't catch any bugs."Bernard Helyer" <b.helyer gmail.com> wrote in message news:j2ithq$12kd$1 digitalmars.com...A warning if anything. I've never encountered a situation where code was made unreachable by accident. I also get "unreachable code" warnings periodically, for code that is absolutely reachable. I don't want my code to not compile simply because the compiler can't perform adequate flow analysis.I asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=20&t=1153378&p=21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the linked forum post for more details ).No. That would be a royal pain in the ass during debugging. I expect to be able to stick a "return xxxx;" anywhere I want to test something and not have the compiler crap out because I didn't deal with the overhead of commenting out the rest. A warning might be nice, though.
Aug 21 2011
Was this broken condition something that could have been detected statically= ? I've encountered plenty of broken conditions, but I've never had a compil= er correctly flag one such. Sent from my iPhone On Aug 21, 2011, at 12:39 PM, Don <nospam nospam.com> wrote:Sean Kelly wrote:1 digitalmars.com...On Aug 18, 2011, at 10:29 AM, Nick Sabalausky wrote:"Bernard Helyer" <b.helyer gmail.com> wrote in message news:j2ithq$12kd$=edI asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=3D20&t=3D1153378&p=3D21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the link=e able to stick a "return xxxx;" anywhere I want to test something and not h= ave the compiler crap out because I didn't deal with the overhead of comment= ing out the rest.forum post for more details ).No. That would be a royal pain in the ass during debugging. I expect to b=made unreachable by accident. I also get "unreachable code" warnings perio= dically, for code that is absolutely reachable. I don't want my code to not= compile simply because the compiler can't perform adequate flow analysis.=20 A warning might be nice, though.A warning if anything. I've never encountered a situation where code was==20 I have encountered bugs of the form: if (cond) { /* unreachable */ } and the cond was unintentionally always false. The last time I encountered=such a bug was last week. I'm surprised your experience is so different.=20 It's crucial that it should never report "unreachable" if it is unsure (no=t even a warning).But I think conditional compilation is a huge problem -- code may be valid=under different compilation conditions. I suspect that to eliminate all the= false positives, it'd have to be so conservative, that it wouldn't catch an= y bugs.=20
Aug 22 2011
Sean Kelly wrote:Was this broken condition something that could have been detected statically? I've encountered plenty of broken conditions, but I've never had a compiler correctly flag one such.Yes. if (a > C1 && a < C2) ... where C1, C2 are compile-time constants, and C1 > C2. (correct condition was: a > C2 && a < C1)Sent from my iPhone On Aug 21, 2011, at 12:39 PM, Don <nospam nospam.com> wrote:Sean Kelly wrote:On Aug 18, 2011, at 10:29 AM, Nick Sabalausky wrote:I have encountered bugs of the form: if (cond) { /* unreachable */ } and the cond was unintentionally always false. The last time I encountered such a bug was last week. I'm surprised your experience is so different. It's crucial that it should never report "unreachable" if it is unsure (not even a warning). But I think conditional compilation is a huge problem -- code may be valid under different compilation conditions. I suspect that to eliminate all the false positives, it'd have to be so conservative, that it wouldn't catch any bugs."Bernard Helyer" <b.helyer gmail.com> wrote in message news:j2ithq$12kd$1 digitalmars.com...A warning if anything. I've never encountered a situation where code was made unreachable by accident. I also get "unreachable code" warnings periodically, for code that is absolutely reachable. I don't want my code to not compile simply because the compiler can't perform adequate flow analysis.I asked the Ars forums ( http://arstechnica.com/civis/viewtopic.php? f=20&t=1153378&p=21965411 ) and I ask the same of you: should unambiguously unreachable code be an error or a warning? ( see the linked forum post for more details ).No. That would be a royal pain in the ass during debugging. I expect to be able to stick a "return xxxx;" anywhere I want to test something and not have the compiler crap out because I didn't deal with the overhead of commenting out the rest. A warning might be nice, though.
Aug 23 2011
On Aug 23, 2011, at 6:04 AM, Don wrote:Sean Kelly wrote:statically? I've encountered plenty of broken conditions, but I've = never had a compiler correctly flag one such.Was this broken condition something that could have been detected ==20 Yes. =20 if (a > C1 && a < C2) ... =20 where C1, C2 are compile-time constants, and C1 > C2. (correct condition was: a > C2 && a < C1)Huh=85 perhaps the issue is simply that I don't tend to have many = complex conditionals involving comparisons with numeric constants. The = tricky ones most often involve the result of at least one function call, = and I suspect there's little that can be statically determined about = those.=
Aug 24 2011