[Bug other/23572] No warning for assigning a value to a 'float' variable that overflows with option -Wextra

2005-08-28 Thread qiyaoltc at cn dot ibm dot com

--- Additional Comments From qiyaoltc at cn dot ibm dot com  2005-08-29 
02:57 ---
OK.
GCC version: 3.4.3 20050227 (Red Hat 3.4.3-22.1)
GNU C Library: stable release version 2.3.4
OS : Red Hat Enterprise Linux AS release 4 (Nahant Update 1)

I write a small example named overflow-test.c, here is the source code:

  1 #includestdio.h
  2 int main()
  3 {
  4   /* overflow.  */
  5   float f1 = 3.5E+38;
  6   /* underflow.  */
  7   float f2 = 3.3E-46;
  8   /* overflow.  */
  9   double d1 = 1.9E+308;
 10   /* underflow.  */
 11   double d2 = 1.4E-325;
 12   /* overflow, 2**32.  */
 13   int i = 4294967296;
 14
 15   printf(%e,%e,%e,%e\n,f1,f2,d1,d2);
 16   printf(%d\n,i);
 17   return 0;
 18 }

And I compile it like this:
[EMAIL PROTECTED] gcc -o overflow-test -Wextra -Wall -g overflow-test.c
overflow-test.c: In function `main':
overflow-test.c:13: warning: integer constant is too large for long type
overflow-test.c:13: warning: overflow in implicit constant conversion

I run it,
[EMAIL PROTECTED] ./overflow-test
inf,0.00e+00,inf,0.00e+00
0


I hope this example would be helpful.  Any comments are highly aprreciated!

-- 


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


[Bug other/23572] No warning for assigning a value to a 'float' variable that overflows with option -Wextra

2005-08-28 Thread qiyaoltc at cn dot ibm dot com

--- Additional Comments From qiyaoltc at cn dot ibm dot com  2005-08-29 
05:00 ---
I add suffix f to the end of float constants at line 5 and line 7, and add
option -pedantic, the output from gcc is like this:

overflow-test.c:5: warning: floating constant exceeds range of float
overflow-test.c:9: warning: floating constant exceeds range of double
overflow-test.c:13: warning: integer constant is too large for long type
overflow-test.c:13: warning: overflow in implicit constant conversion

It seems that gcc has checked initialization which caused overflow, but do not
check underflow, that is to say:
1 GCC does not check underflow event, at least options -pedantic does not enable
underflow check.
2 If there is some mechanism in GCC internal to check underflow and overflow,
there is a bug in gcc info about the description of -Wextra option.

Could you tell me what I could do to this problem?  Maybe, it is impossible for
me to fix it, but I just want to do something more.  Please give me some
suggestions and I will try to do it.

Thanks.

-- 


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


[Bug other/23572] New: No warning for assigning a value to a 'float' variable that overflows with option -Wextra

2005-08-26 Thread qiyaoltc at cn dot ibm dot com
I tried compilers 4.1.0 through mainline and none of them warn about nitializing
a float variable with a value that will overflow, underflow, or lose precision
for -W or -Wextra.

But in GCC info, It is said like this:
in GCC info(GCC 3.3.4).
 `-Wextra'
  (This option used to be called `-W'.  The older name is still
  supported, but the newer name is more descriptive.)  Print extra
  warning messages for these events:
 
  * Any of several floating-point events that often indicate
  errors, such as overflow, underflow, loss of precision, etc.


Is this a bug either in GCC or a bug in documentation?

-- 
   Summary: No warning for assigning a value to a 'float' variable
that overflows with option -Wextra
   Product: gcc
   Version: 4.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: other
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: qiyaoltc at cn dot ibm dot com
CC: gcc-bugs at gcc dot gnu dot org,janis187 at us dot ibm
dot com
 GCC build triplet: ppc64-redhat-linux
  GCC host triplet: ppc64-redhat-linux
GCC target triplet: ppc64-redhat-linux


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