diff options
author | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-19 13:32:03 +0000 |
---|---|---|
committer | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-19 13:32:03 +0000 |
commit | 7ee0d2277e23c2e52f6d6929708039e4aac9b153 (patch) | |
tree | 98d10e457cbf659848ab680b6b1b3e192890e140 /gcc/testsuite/gcc.dg/Wsign-conversion.c | |
parent | df3d6232299393f4c995d54e13ae47611bc8d823 (diff) | |
download | gcc-7ee0d2277e23c2e52f6d6929708039e4aac9b153.tar.gz |
2007-05-19 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* doc/invoke.texi (Warning Options): Add -Wconversion-sign.
(Wconversion): Update description.
(Wconversion-sign): New.
* c.opt (Wconversion-sign): New.
* c-opts.c (c_common_post_options): Uninitialized Wconversion-sign
means disabled for C++. Otherwise, take the status of Wconversion.
* c-common.c (conversion_warning): Warn with either Wconversion or
Wconversion-sign.
(warnings_for_convert_and_check): Conditions are already checked by
conversion_warning.
(convert_and_check): Don't check warnings if the conversion failed.
cp/
* cvt.c (cp_convert_and_check): Don't check warnings if the
conversion failed.
testsuite/
* gcc.dg/Wconversion-integer.c: Group testcases and add more.
* gcc.dg/Wconversion-sign.c: New.
* gcc.dg/Wconversion-integer-no-sign.c: New.
* g++.dg/warn/Wconversion-integer.C: Move some warnings to
Wconversion-sign.C
* g++.dg/warn/Wconversion-sign.C: New.
* g++.old-deja/g++.other/warn4.C: Update.
* g++.dg/warn/Wconversion1.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@124856 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/Wsign-conversion.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/Wsign-conversion.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Wsign-conversion.c b/gcc/testsuite/gcc.dg/Wsign-conversion.c new file mode 100644 index 00000000000..45edd3b4361 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wsign-conversion.c @@ -0,0 +1,96 @@ +/* Test for diagnostics for implicit conversions between signed and + unsigned integer types. + These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c */ + +/* { dg-do compile } */ +/* { dg-options "-std=c99 -fsigned-char -Wsign-conversion" } */ +#include <limits.h> + +void fsc (signed char sc); +void fuc (unsigned char uc); +unsigned fui (unsigned int ui); +void fsi (signed int ui); + +void h (int x) +{ + unsigned int ui = 3; + int si = 3; + unsigned char uc = 3; + signed char sc = 3; + + uc = ui; + uc = si; + sc = ui; + sc = si; + fuc (ui); + fuc (si); + fsc (ui); + fsc (si); + + fsi (si); + fui (ui); + fsi (uc); + si = uc; + fui (uc); + ui = uc; + fui ('A'); + ui = 'A'; + fsi ('A'); + si = 'A'; + fuc ('A'); + uc = 'A'; + + uc = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = x ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = x ? 1 : -1; + uc = x ? SCHAR_MIN : 1; + ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = x ? 1 : -1; /* { dg-warning "conversion" } */ + ui = ui ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */ + + fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fsi (0x80000000); /* { dg-warning "conversion" } */ + si = 0x80000000; /* { dg-warning "conversion" } */ + + + fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */ + si = UINT_MAX - 1; /* { dg-warning "conversion" } */ + fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */ + si = UINT_MAX - 1U; /* { dg-warning "conversion" } */ + fsi (UINT_MAX/3U); + si = UINT_MAX/3U; + fsi (UINT_MAX/3); + si = UINT_MAX/3; + fui (UINT_MAX - 1); + ui = UINT_MAX - 1; + + uc = (unsigned char) -1; + ui = -1 * (1 * -1); + ui = (unsigned) -1; + + fsc (uc); /* { dg-warning "conversion" } */ + sc = uc; /* { dg-warning "conversion" } */ + fuc (sc); /* { dg-warning "conversion" } */ + uc = sc; /* { dg-warning "conversion" } */ + fsi (ui); /* { dg-warning "conversion" } */ + si = ui; /* { dg-warning "conversion" } */ + fui (si); /* { dg-warning "conversion" } */ + ui = si; /* { dg-warning "conversion" } */ + fui (sc); /* { dg-warning "conversion" } */ + ui = sc; /* { dg-warning "conversion" } */ +} + +unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + + |