diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2007-03-22 23:04:24 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2007-03-22 23:04:24 +0000 |
commit | 92ef5cf99970d490ebdd508c774b86bd4a821887 (patch) | |
tree | 72ccc17238a98a5218797e0019368cff25e58e57 /gcc/c-lex.c | |
parent | efa591c57ef118d3e21c0a1550a31fb00d75407e (diff) | |
download | gcc-92ef5cf99970d490ebdd508c774b86bd4a821887.zip gcc-92ef5cf99970d490ebdd508c774b86bd4a821887.tar.gz gcc-92ef5cf99970d490ebdd508c774b86bd4a821887.tar.bz2 |
re PR other/23572 (No warning for assigning a value to a 'float' variable that overflows with option -Wextra)
2007-03-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR other/23572
* c-lex.c (interpret_float): On overflow, emit pedantic warning if
infinities not supported, otherwise emit warning if -Woverflow. On
underflow, emit warning if -Woverflow.
* real.c (real_from_string): Return -1 if underflow, +1 if overflow
and 0 otherwise.
* real.h (real_from_string): Update declaration
testsuite/
* gcc.dg/float-range-4.c: New.
* gcc.dg/float-range-1.c: Update. Test for a warning.
* gcc.dg/float-range-3.c: New.
* gcc.dg/float-range-5.c: New.
From-SVN: r123137
Diffstat (limited to 'gcc/c-lex.c')
-rw-r--r-- | gcc/c-lex.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 108bc5c..a89643c 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -681,11 +681,23 @@ interpret_float (const cpp_token *token, unsigned int flags) /* Both C and C++ require a diagnostic for a floating constant outside the range of representable values of its type. Since we - have __builtin_inf* to produce an infinity, it might now be - appropriate for this to be a mandatory pedwarn rather than - conditioned on -pedantic. */ - if (REAL_VALUE_ISINF (real) && pedantic) - pedwarn ("floating constant exceeds range of %qT", type); + have __builtin_inf* to produce an infinity, this is now a + mandatory pedwarn if the target does not support infinities. */ + if (REAL_VALUE_ISINF (real)) + { + if (!MODE_HAS_INFINITIES (TYPE_MODE (type))) + pedwarn ("floating constant exceeds range of %qT", type); + else + warning (OPT_Woverflow, "floating constant exceeds range of %qT", type); + } + /* We also give a warning if the value underflows. */ + else if (REAL_VALUES_EQUAL (real, dconst0)) + { + REAL_VALUE_TYPE realvoidmode; + int overflow = real_from_string (&realvoidmode, copy); + if (overflow < 0 || !REAL_VALUES_EQUAL (realvoidmode, dconst0)) + warning (OPT_Woverflow, "floating constant truncated to zero"); + } /* Create a node with determined type and value. */ value = build_real (type, real); |