aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/Wfloat-conversion.c
blob: e872755902deeab3081e2cabe26acfc35c9d5b6e (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
/* Test for diagnostics for Wconversion for floating-point.  */

/* { dg-do compile } */
/* { dg-options "-std=c99 -Wfloat-conversion" { target c } } */
/* { dg-options "-Wfloat-conversion" { target c++ } } */
/* { dg-require-effective-target large_double } */
/* { dg-require-effective-target int32plus } */
/* { dg-require-effective-target double64plus } */
#include <limits.h>

float  vfloat;
double vdouble;
long double vlongdouble;
int bar;

void fsi (signed int x);
void fui (unsigned int x);
void ffloat (float f);
void fdouble (double d);
void flongdouble (long double ld);

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

  ffloat (3.1); /* { dg-warning "conversion to 'float' alters 'double' constant value" } */
  vfloat = 3.1; /* { dg-warning "conversion to 'float' alters 'double' constant value" } */
  ffloat (3.1L); /* { dg-warning "conversion to 'float' alters 'long double' constant value" } */
  vfloat = 3.1L;  /* { dg-warning "conversion to 'float' alters 'long double' constant value" } */
  fdouble (3.1L); /* { dg-warning "conversion to 'double' alters 'long double' constant value" "" { target large_long_double } } */
  vdouble = 3.1L; /* { dg-warning "conversion to 'double' alters 'long double' constant value" "" { target large_long_double } } */
  ffloat (vdouble); /* { dg-warning "conversion to 'float' from 'double' may alter its value" } */
  vfloat = vdouble; /* { dg-warning "conversion to 'float' from 'double' may alter its value" } */
  ffloat (vlongdouble); /* { dg-warning "conversion to 'float' from 'long double' may alter its value" } */
  vfloat = vlongdouble; /* { dg-warning "conversion to 'float' from 'long double' may alter its value" } */
  fdouble (vlongdouble); /* { dg-warning "conversion to 'double' from 'long double' may alter its value" "" { target large_long_double } } */
  vdouble = vlongdouble; /* { dg-warning "conversion to 'double' from 'long double' may alter its value" "" { target large_long_double } } */

  fsi (3.1f); /* { dg-warning "conversion to 'int' alters 'float' constant value" } */
  si = 3.1f; /* { dg-warning "conversion to 'int' alters 'float' constant value" } */
  fsi (3.1);  /* { dg-warning "conversion to 'int' alters 'double' constant value" } */
  si = 3.1;  /* { dg-warning "conversion to 'int' alters 'double' constant value" } */
  fsi (d);    /* { dg-warning "conversion to 'int' from 'double' may alter its value" } */
  si = d;    /* { dg-warning "conversion to 'int' from 'double' may alter its value" } */
  ffloat (INT_MAX);  /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
  vfloat = INT_MAX;  /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
  ffloat (16777217); /* { dg-warning "conversion to 'float' alters 'int' constant value" } */
  vfloat = 16777217; /* { dg-warning "conversion to 'float' alters 'int' constant value" } */

  sc = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion to 'signed char' alters 'double' constant value" } */
  uc = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion to 'unsigned char' alters 'double' constant value" } */
}