summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/pr12242.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/warn/pr12242.C
downloadcbb-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/g++.dg/warn/pr12242.C')
-rw-r--r--gcc/testsuite/g++.dg/warn/pr12242.C57
1 files changed, 57 insertions, 0 deletions
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<X> (10); // { dg-warning "unspecified" }
+ X b = static_cast<X> (0);
+ X c = static_cast<X> (1);
+ X d = static_cast<X> (2); // { dg-warning "unspecified" }
+ X f = static_cast<X> ((int)A);
+ X g = static_cast<X> (B);
+ X h = static_cast<X> (C);
+ X e = static_cast<X> (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" }
+ );
+}
+