Bug 290483 - [compiler] Suppress "Dead Code" warning if code block is protected by "if(0==1)"
Summary: [compiler] Suppress "Dead Code" warning if code block is protected by "if(0==1)"
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-25 03:25 EDT by Aaron Digulla CLA
Modified: 2009-10-27 07:38 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Digulla CLA 2009-09-25 03:25:28 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Build Identifier: I20090611-1540

I'm using the construct "if (0 == 1)" to quickly enable/disable a code block. With 3.5, I get a "Dead Code" warning.

I'd like an option to be able to keep the "Dead Code" warning for other code but it shouldn't warn for code like this:

   if (0 == 1) {...}

and

   boolean enable = 0 == 1;
   if (enable) {...}

PS: The advantage of "0 == 1" instead of commenting out the code: I don't have to fix the imports and/or local variables plus it's only a single character change in the VCS.

Reproducible: Always
Comment 1 Stephan Herrmann CLA 2009-09-25 08:36:50 EDT
Please see bug 256463.

Wouldn't the pattern supported in 3.5 work for you, too?
(hint: use a constant)
Comment 2 Olivier Thomann CLA 2009-09-25 08:40:28 EDT
Why not simply using "if (false) ..."?
This won't be different from what you are writing.
Comment 3 Aaron Digulla CLA 2009-09-25 09:20:38 EDT
(In reply to comment #2)
> Why not simply using "if (false) ..."?
> This won't be different from what you are writing.

Yes, it would be: I would have to change more than a single character to flip the condition. Also the chance to encounter "if (0 == 1)" anywhere else in the code is pretty low which makes it a good candidate to guard debug code.
Comment 4 Aaron Digulla CLA 2009-09-25 09:23:28 EDT
(In reply to comment #1)
> Please see bug 256463.
> 
> Wouldn't the pattern supported in 3.5 work for you, too?
> (hint: use a constant)

Thanks for the hint. It solves half of my problem (my second case above works with 3.5; I didn't actually try it before reporting the bug).

So my bug report is now to allow "if (0 == 1)" in addition to what bug 256463  fixes.

I'd rather track this with a new bug since bug 256463 is already closed.
Comment 5 Olivier Thomann CLA 2009-09-25 09:27:28 EDT
The chances should not be higher to encounter "if (false)...".
Comment 6 Aaron Digulla CLA 2009-09-25 09:42:00 EDT
(In reply to comment #5)
> The chances should not be higher to encounter "if (false)...".

Then do it. With "if (false)", you have to select "false" and replace it with "true". That's four to nine keys pressed.

With "if (0 == 1)", it's two keys: Select or delete the "0", press "1".

Which one is less work? :)
Comment 7 Stephan Herrmann CLA 2009-09-25 11:55:43 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > The chances should not be higher to encounter "if (false)...".
> 
> Then do it. With "if (false)", you have to select "false" and replace it with
> "true". That's four to nine keys pressed.
> 
> With "if (0 == 1)", it's two keys: Select or delete the "0", press "1".
> 
> Which one is less work? :)

If you're really concerned about a few keystrokes, 
why don't you let "!" be your friend? ;-)

  DEBUG = true;

  if (DEBUG) stmt;

edit

  DEBUG = !true;

Sound much easier than introducing more heuristics into the tool, no?
Comment 8 Olivier Thomann CLA 2009-09-25 12:13:20 EDT
We cannot support everyone's dead code pattern. I believe we support the more comment ones.
This is clearly low priority. Feel free to provide a patch.
Comment 9 Olivier Thomann CLA 2009-10-01 11:51:45 EDT
Closing as WONTFIX.
No plan to add this code pattern.
if (DEBUG) or if (!DEBUG) is sufficient. We don't want to add special cases for each of the existing code patterns.
Comment 10 Ayushman Jain CLA 2009-10-27 06:10:05 EDT
Verified for 3.6M3