summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wconversion-5.c
blob: be749a9a65f5b9951c814c317f09dd618b1457f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* PR c++/34198 */
/* { dg-do compile } */
/* { dg-options "-O2 -Wconversion" } */

signed char sc;
unsigned char uc;
short int ss;
unsigned short int us;
int si;
unsigned int ui;

void test1 (void)
{
  int a = uc & 0xff;
  int b = sc & 0x7f;
  int c = 0xff & uc;
  int d = 0x7f & sc;
  int e = uc & sc;
  unsigned char f = (int) uc;
  signed char g = (int) sc;
  unsigned char h = (unsigned int) (short int) uc;
  signed char i = (int) (unsigned short int) sc;	/* { dg-warning "may alter its value" "" { target { int32plus } } } */
  unsigned char j = (unsigned int) (short int) us;	/* { dg-warning "may alter its value" } */
  signed char k = (int) (unsigned short int) ss;	/* { dg-warning "may alter its value" } */
}

void test2 (void)
{
  signed char a = (unsigned char) sc;		/* { dg-warning "may change the sign" } */
  unsigned char b = (signed char) uc;		/* { dg-warning "may change the sign" } */
  signed char c = (int) (unsigned char) sc;	/* { dg-warning "may change the sign" } */
  unsigned char d = (int) (signed char) uc;	/* { dg-warning "may change the sign" } */
  int e = (unsigned int) si;			/* { dg-warning "may change the sign" } */
  unsigned int f = (int) ui;			/* { dg-warning "may change the sign" } */
}