OSDN Git Service

Add NIOS2 support. Code from SourceyG++.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / warn / pr12242.C
1 // PR 12242: should warn about out-of-range int->enum conversions
2 // { dg-do compile }
3 // { dg-options "-Wconversion -fpermissive" }
4 enum X { A };
5 enum Y { B, C, D };
6
7 void example ()
8 {
9   int i = 5;
10   X x;
11   Y y;
12   
13   x = 10;  // { dg-warning "invalid conversion from .int. to .X." }
14            // { dg-warning "unspecified" "" { target *-*-* } 13 }
15   x = 1;   // { dg-warning "invalid conversion from .int. to .X." }
16   x = C;   // { dg-error "cannot convert .Y. to .X. in assignment" }  
17   x = D;   // { dg-error "cannot convert .Y. to .X. in assignment" }  
18   y = A;   // { dg-error "cannot convert .X. to .Y. in assignment" }  
19   x = y;   // { dg-error "cannot convert .Y. to .X. in assignment" }  
20   x = i;   // { dg-warning "invalid conversion from .int. to .X."  }
21 }
22
23 void foo () 
24 {
25   X a = static_cast<X> (10); // { dg-warning "unspecified" }
26   X b = static_cast<X> (0);
27   X c = static_cast<X> (1);
28   X d = static_cast<X> (2); // { dg-warning "unspecified" }
29   X f = static_cast<X> ((int)A);
30   X g = static_cast<X> (B);
31   X h = static_cast<X> (C);
32   X e = static_cast<X> (D); // { dg-warning "unspecified" }
33 }
34
35 enum QEvent { x = 42 }; 
36  
37 int bar()
38
39   QEvent x = ( QEvent ) 42000; // { dg-warning "unspecified" }
40   return ( int ) x; 
41 }
42
43 enum W {a,b,c};
44 enum Z {d,e,f,g};
45 void bazz (int, int, int, int);
46
47 void baz() {
48   int three = 3;
49   int four = 4;
50   bazz (
51         W(three), 
52         W(3), 
53         Z(four), 
54         Z(4) // { dg-warning "unspecified" }
55         );
56 }
57