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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 693 jeremybenn
/* PR 35635 */
2
/* { dg-do compile } */
3
/* { dg-options "-Wconversion -Wsign-conversion" } */
4
 
5
struct unsigned_bit {
6
  unsigned int x:1;
7
} unsigned_bit;
8
struct signed_bit {
9
  int x:1;
10
} signed_bit;
11
int bar;
12
int bar2;
13
 
14
void func1()
15
{
16
  /* The result of boolean operators fits in unsiged int:1, thus do
17
     not warn.  */
18
  unsigned_bit.x = (bar != 0); /* { dg-bogus "conversion" } */
19
  unsigned_bit.x = (bar == 0); /* { dg-bogus "conversion" } */
20
  unsigned_bit.x = (bar <= 0); /* { dg-bogus "conversion" } */
21
  unsigned_bit.x = (bar >= 0); /* { dg-bogus "conversion" } */
22
  unsigned_bit.x = (bar < 0);  /* { dg-bogus "conversion" } */
23
  unsigned_bit.x = (bar > 0);  /* { dg-bogus "conversion" } */
24
  unsigned_bit.x = !bar;       /* { dg-bogus "conversion" } */
25
  unsigned_bit.x = (bar || bar2); /* { dg-bogus "conversion" } */
26
  unsigned_bit.x = (bar && bar2); /* { dg-bogus "conversion" } */
27
 
28
  /* Both branches of ? fit in the destination, thus do not warn.  */
29
  unsigned_bit.x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */
30
  unsigned_bit.x = bar != 0 ? 1.0 : 0.0;  /* { dg-bogus "conversion" } */
31
 
32
  /* At least one branch of ? does not fit in the destination, thus
33
     warn.  */
34
  unsigned_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */
35
  unsigned_bit.x = bar != 0 ? 0 : -1; /* { dg-warning "conver" } */
36
}
37
 
38
void func2()
39
{
40
  signed char schar_x;
41
 
42
  /* Both branches of ? fit in the destination, thus do not warn.  */
43
  schar_x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */
44
  schar_x = bar != 0 ? 2.0 : 10; /* { dg-bogus "conversion" } */
45
 
46
  /* At least one branch of ? does not fit in the destination, thus
47
     warn.  */
48
  schar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
49
  schar_x = bar != 0 ? (signed char) 1024: -1024; /* { dg-warning "conversion" } */
50
}
51
 
52
 
53
 
54
void func3()
55
{
56
  unsigned char uchar_x;
57
 
58
  /* Both branches of ? fit in the destination, thus do not warn.  */
59
  uchar_x = bar != 0 ? 1 : 0;
60
  uchar_x = bar != 0 ? 2.0 : 10;
61
 
62
  /* At least one branch of ? does not fit in the destination, thus
63
     warn.  */
64
  uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
65
  uchar_x = bar != 0
66
    ? (unsigned char) 1024
67
    : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
68
}
69
 
70
void func4()
71
{
72
  signed_bit.x = -1; /* { dg-bogus "conversion" } */
73
  signed_bit.x = bar != 0 ? -1.0 : 0.0;  /* { dg-bogus "conversion" } */
74
  signed_bit.x = bar != 0 ? -1 : 0; /* { dg-bogus "conversion" } */
75
 
76
  signed_bit.x = 1;          /* { dg-warning "conversion" } */
77
  signed_bit.x = (bar != 0); /* { dg-warning "conversion" } */
78
  signed_bit.x = (bar == 0); /* { dg-warning "conversion" } */
79
  signed_bit.x = (bar <= 0); /* { dg-warning "conversion" } */
80
  signed_bit.x = (bar >= 0); /* { dg-warning "conversion" } */
81
  signed_bit.x = (bar < 0);  /* { dg-warning "conversion" } */
82
  signed_bit.x = (bar > 0);  /* { dg-warning "conversion" } */
83
  signed_bit.x = !bar;       /* { dg-warning "conversion" } */
84
  signed_bit.x = (bar || bar2); /* { dg-warning "conversion" } */
85
  signed_bit.x = (bar && bar2); /* { dg-warning "conversion" } */
86
  signed_bit.x = bar != 0 ? 1 : 0; /* { dg-warning "conversion" } */
87
  signed_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */
88
}
89
 

powered by: WebSVN 2.1.0

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