[Bug debug/35188] New: Missing a warning: if-condition is inherently blocking the if-body

2008-02-13 Thread tuttle at sandbox dot cz
I would consider to be great when this code

if ( (var == 1) && (var == 2) ) { body }

would cause a warning, that the body is
unreachable under any circumstances.

I have made several mistakes like this in the
past and it is annoying to track down...


-- 
   Summary: Missing a warning: if-condition is inherently blocking
the if-body
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: enhancement
  Priority: P3
 Component: debug
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tuttle at sandbox dot cz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35188



[Bug middle-end/35188] Missing a warning: if-condition is inherently blocking the if-body

2008-02-13 Thread tuttle at sandbox dot cz


--- Comment #2 from tuttle at sandbox dot cz  2008-02-13 21:41 ---
(In reply to comment #1)
> -Wunreachable-code should warn already.
> -- Pinski

I've tried -Wunreachable-code before submitting this enhancement request.

gcc 4.1.3 in Ubuntu GG does not warn.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35188



[Bug middle-end/35188] Missing a warning: inherently false expressions

2008-02-16 Thread tuttle at sandbox dot cz


--- Comment #5 from tuttle at sandbox dot cz  2008-02-16 14:12 ---
I think we could generalize a bit: This in fact is not bound to if-statement or
code reachability.

Tried the following with snapshot gcc-4.3-20080215 -Wextra -Wall
-Wunreachable-code.

#include 

int main()
{
  int var1 = (1 && 0);   /* does not warn */

  printf("var1 = %d\n", var1);  /* outputs: var1 = 0 */

  if ( 0 && 1 )
printf("FIRST\n");   /* warns ok: printf unreachable */

  if ( 0 && (var1 == 10) )
printf("SECOND\n");  /* warns ok: printf unreachable */

  if ( (var1 == 10) && (var1 == 20) )
printf("THIRD\n");   /* does not warn */

  return 0;
}

Please do not expect a compilable testcase from me. 1) I don't know whether
this is a bug, 2) have no experience in gcc testcases.

I just tried to provide an idea.

With deep respect,

Vlada Macek


-- 

tuttle at sandbox dot cz changed:

   What|Removed |Added

Summary|Missing a warning: if-  |Missing a warning:
   |condition is inherently |inherently false expressions
   |blocking the if-body|
Version|4.1.3   |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35188



[Bug middle-end/35188] Missing a warning: inherently false expressions

2008-02-16 Thread tuttle at sandbox dot cz


--- Comment #7 from tuttle at sandbox dot cz  2008-02-16 18:09 ---
That's great, even my older gcc 4.1.3 warns for every if-body with -O1
-Wunreachable code. Shame on me I did not came with -O1 myself, sorry.

Anyway my first code line

int var1 = (1 && 0);

is not about the execution reachability. It may be considered as a simplest
form of inherently false expressions such as

( (var==10) && (var==20) )

that I would consider good to produce warnings. But that would AFAIK need a
completely new kind of warnings (as well as checking code?).

Sorry for bugging everybody with such minor thing. Feel free to close the bug.

VM


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35188