OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [warn/] [pr12242.C] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// 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 (10); // { dg-warning "unspecified" }
26
  X b = static_cast (0);
27
  X c = static_cast (1);
28
  X d = static_cast (2); // { dg-warning "unspecified" }
29
  X f = static_cast ((int)A);
30
  X g = static_cast (B);
31
  X h = static_cast (C);
32
  X e = static_cast (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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.