From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- gcc/testsuite/g++.dg/warn/pr12242.C | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/pr12242.C (limited to 'gcc/testsuite/g++.dg/warn/pr12242.C') diff --git a/gcc/testsuite/g++.dg/warn/pr12242.C b/gcc/testsuite/g++.dg/warn/pr12242.C new file mode 100644 index 000000000..e858c5405 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr12242.C @@ -0,0 +1,57 @@ +// PR 12242: should warn about out-of-range int->enum conversions +// { dg-do compile } +// { dg-options "-Wconversion -fpermissive" } +enum X { A }; +enum Y { B, C, D }; + +void example () +{ + int i = 5; + X x; + Y y; + + x = 10; // { dg-warning "invalid conversion from .int. to .X." } + // { dg-warning "unspecified" "" { target *-*-* } 13 } + x = 1; // { dg-warning "invalid conversion from .int. to .X." } + x = C; // { dg-error "cannot convert .Y. to .X. in assignment" } + x = D; // { dg-error "cannot convert .Y. to .X. in assignment" } + y = A; // { dg-error "cannot convert .X. to .Y. in assignment" } + x = y; // { dg-error "cannot convert .Y. to .X. in assignment" } + x = i; // { dg-warning "invalid conversion from .int. to .X." } +} + +void foo () +{ + X a = static_cast (10); // { dg-warning "unspecified" } + X b = static_cast (0); + X c = static_cast (1); + X d = static_cast (2); // { dg-warning "unspecified" } + X f = static_cast ((int)A); + X g = static_cast (B); + X h = static_cast (C); + X e = static_cast (D); // { dg-warning "unspecified" } +} + +enum QEvent { x = 42 }; + +int bar() +{ + QEvent x = ( QEvent ) 42000; // { dg-warning "unspecified" } + return ( int ) x; +} + +enum W {a,b,c}; +enum Z {d,e,f,g}; +void bazz (int, int, int, int); + +void baz() { + int three = 3; + int four = 4; + bazz ( + W(three), + W(3), + Z(four), + Z(4) // { dg-warning "unspecified" } + ); +} + -- cgit v1.2.3