summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/Wconversion-real-integer.C
blob: 282ac13da582d835b78888aaeeb8c85733fd6f80 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Test for diagnostics for Wconversion between floating-point and
   integers. C++ equivalent of
   gcc/testsuite/gcc.dg/Wconversion-real-integer.c */

/* { dg-do compile }
/* { dg-options "-Wconversion" } */
/* { dg-require-effective-target int32plus } */
#include <limits.h>

void fsi (signed int x);
void fui (unsigned int x);
void ffloat (float x);
void fdouble (double x);

float  vfloat;
double vdouble;

void h (void)
{
  unsigned int ui = 3;
  int   si = 3;
  unsigned char uc = 3;
  signed char sc = 3;
  float  f = 3;
  double d = 3;

  fsi (3.1f); /* { dg-warning "conversion" } */
  si = 3.1f; /* { dg-warning "conversion" } */
  fsi (3.1);  /* { dg-warning "conversion" } */
  si = 3.1;  /* { dg-warning "conversion" } */
  fsi (d);    /* { dg-warning "conversion" } */
  si = d;    /* { dg-warning "conversion" } */
  fui (-1.0); /* { dg-warning "overflow" } */
  ui = -1.0;   /* { dg-warning "overflow" } */
  ffloat (INT_MAX);  /* { dg-warning "conversion" } */
  vfloat = INT_MAX;  /* { dg-warning "conversion" } */
  ffloat (16777217); /* { dg-warning "conversion" } */
  vfloat = 16777217; /* { dg-warning "conversion" } */
  ffloat (si); /* { dg-warning "conversion" } */
  vfloat = si; /* { dg-warning "conversion" } */
  ffloat (ui); /* { dg-warning "conversion" } */
  vfloat = ui; /* { dg-warning "conversion" } */

  fsi (3);
  si = 3;
  fsi (3.0f);
  si = 3.0f;
  fsi (3.0);
  si = 3.0;
  fsi (16777217.0f);
  si = 16777217.0f;
  fsi ((int) 3.1);
  si = (int) 3.1;
  ffloat (3U);
  vfloat = 3U;
  ffloat (3);
  vfloat = 3;
  ffloat (INT_MIN);
  vfloat = INT_MIN;
  ffloat (uc);
  vfloat = uc;
  ffloat (sc);
  vfloat = sc;

  fdouble (UINT_MAX);
  vdouble = UINT_MAX;
  fdouble (ui);
  vdouble = ui;
  fdouble (si);
  vdouble = si;
}


void fss (signed short x);
void fus (unsigned short x);
void fsc (signed char x);
void fuc (unsigned char x);

void h2 (void)
{
  unsigned short int us;
  short int   ss;
  unsigned char uc;
  signed char sc;
  
  fss (4294967294.0); /* { dg-warning "conversion" } */
  ss = 4294967294.0; /* { dg-warning "conversion" } */
  fss (-4294967294.0);  /* { dg-warning "conversion" } */
  ss = -4294967294.0;  /* { dg-warning "conversion" } */
  fus (4294967294.0); /* { dg-warning "conversion" } */
  us = 4294967294.0; /* { dg-warning "conversion" } */
  fus (-4294967294.0);  /* { dg-warning "conversion" } */
  us = -4294967294.0;  /* { dg-warning "conversion" } */

  fsc (500.0); /* { dg-warning "conversion" } */
  sc = 500.0; /* { dg-warning "conversion" } */
  fsc (-500.0);  /* { dg-warning "conversion" } */
  sc = -500.0;  /* { dg-warning "conversion" } */
  fuc (500.0); /* { dg-warning "conversion" } */
  uc = 500.0; /* { dg-warning "conversion" } */
  fuc (-500.0);  /* { dg-warning "conversion" } */
  uc = -500.0;  /* { dg-warning "conversion" } */

  fss (500.0);
  ss = 500.0;
  fss (-500.0);
  ss = -500.0;
  fus (500.0); 
  us = 500.0; 
  fus (-500.0);   /* { dg-warning "conversion" } */
  us = -500.0;    /* { dg-warning "conversion" } */
}