diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/pr35635.c | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/pr35635.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/pr35635.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/pr35635.c b/gcc/testsuite/gcc.dg/pr35635.c new file mode 100644 index 000000000..45d10a67b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35635.c @@ -0,0 +1,90 @@ +/* PR 35635 */ +/* { dg-do compile } */ +/* { dg-options "-Wconversion -Wsign-conversion" } */ + +struct unsigned_bit { + unsigned int x:1; +} unsigned_bit; +struct signed_bit { + int x:1; +} signed_bit; +int bar; +int bar2; + +void func1() +{ + /* The result of boolean operators fits in unsiged int:1, thus do + not warn. */ + unsigned_bit.x = (bar != 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar == 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar <= 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar >= 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar < 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar > 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = !bar; /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar || bar2); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar && bar2); /* { dg-bogus "conversion" } */ + + /* Both branches of ? fit in the destination, thus do not warn. */ + unsigned_bit.x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */ + unsigned_bit.x = bar != 0 ? 1.0 : 0.0; /* { dg-bogus "conversion" } */ + + /* At least one branch of ? does not fit in the destination, thus + warn. */ + unsigned_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */ + unsigned_bit.x = bar != 0 ? 0 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ +} + +void func2() +{ + signed char schar_x; + + /* Both branches of ? fit in the destination, thus do not warn. */ + schar_x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */ + schar_x = bar != 0 ? 2.0 : 10; /* { dg-bogus "conversion" } */ + + /* At least one branch of ? does not fit in the destination, thus + warn. */ + schar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */ + schar_x = bar != 0 ? (signed char) 1024: -1024; /* { dg-warning "conversion" } */ +} + + + +void func3() +{ + unsigned char uchar_x; + + /* Both branches of ? fit in the destination, thus do not warn. */ + uchar_x = bar != 0 ? 1 : 0; + uchar_x = bar != 0 ? 2.0 : 10; + + /* At least one branch of ? does not fit in the destination, thus + warn. */ + uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */ + uchar_x = bar != 0 + ? (unsigned char) 1024 + : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ +} + +void func4() +{ + signed_bit.x = -1; /* { dg-bogus "conversion" } */ + signed_bit.x = bar != 0 ? -1.0 : 0.0; /* { dg-bogus "conversion" } */ + signed_bit.x = bar != 0 ? -1 : 0; /* { dg-bogus "conversion" } */ + + + signed_bit.x = 1; /* { dg-warning "conversion" } */ + signed_bit.x = (bar != 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar == 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar <= 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar >= 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar < 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar > 0); /* { dg-warning "conversion" } */ + signed_bit.x = !bar; /* { dg-warning "conversion" } */ + signed_bit.x = (bar || bar2); /* { dg-warning "conversion" } */ + signed_bit.x = (bar && bar2); /* { dg-warning "conversion" } */ + signed_bit.x = bar != 0 ? 1 : 0; /* { dg-warning "conversion" } */ + signed_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */ +} + |