Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / testsuite / g++.dg / warn / Wdouble-promotion.C
blob9b4044f77f62695f2cc17513817cedc4f3f0d030
1 /* { dg-do compile } */
2 /* { dg-options "-Wdouble-promotion" } */
4 #include <stddef.h>
6 /* Some targets do not provide <complex.h> so we define I ourselves.  */
7 #define I 1.0iF
8 #define ID ((_Complex double)I)
10 float f;
11 double d;
12 int i;
13 long double ld;
14 _Complex float cf;
15 _Complex double cd;
16 _Complex long double cld;
17 size_t s;
19 extern void varargs_fn (int, ...);
20 extern void double_fn (double);
21 extern float float_fn (void);
23 void 
24 usual_arithmetic_conversions(void) 
26   float local_f;
27   _Complex float local_cf;
29   /* Values of type "float" are implicitly converted to "double" or
30      "long double" due to use in arithmetic with "double" or "long
31      double" operands.  */
32   local_f = f + 1.0;         /* { dg-warning "implicit" } */
33   local_f = f - d;           /* { dg-warning "implicit" } */
34   local_f = 1.0f * 1.0;      /* { dg-warning "implicit" } */
35   local_f = 1.0f / d;        /* { dg-warning "implicit" } */
37   local_cf = cf + 1.0;       /* { dg-warning "implicit" } */
38   local_cf = cf - d;         /* { dg-warning "implicit" } */
39   local_cf = cf + 1.0 * ID;  /* { dg-warning "implicit" } */
40   local_cf = cf - cd;        /* { dg-warning "implicit" } */
41   
42   local_f = i ? f : d;       /* { dg-warning "implicit" } */
43   i = f == d;                /* { dg-warning "implicit" } */
44   i = d != f;                /* { dg-warning "implicit" } */
47 void 
48 default_argument_promotion (void) 
50   /* Because "f" is part of the variable argument list, it is promoted
51      to "double".  */
52   varargs_fn (1, f);   /* { dg-warning "implicit" } */
55 /* There is no warning when an explicit cast is used to perform the
56    conversion.  */
58 void
59 casts (void) 
61   float local_f;
62   _Complex float local_cf;
64   local_f = (double)f + 1.0;                 /* { dg-bogus "implicit" } */
65   local_f = (double)f - d;                   /* { dg-bogus "implicit" } */
66   local_f = (double)1.0f + 1.0;              /* { dg-bogus "implicit" } */
67   local_f = (double)1.0f - d;                /* { dg-bogus "implicit" } */
69   local_cf = (_Complex double)cf + 1.0;      /* { dg-bogus "implicit" } */
70   local_cf = (_Complex double)cf - d;        /* { dg-bogus "implicit" } */
71   local_cf = (_Complex double)cf + 1.0 * ID; /* { dg-bogus "implicit" } */
72   local_cf = (_Complex double)cf - cd;       /* { dg-bogus "implicit" } */
74   local_f = i ? (double)f : d;               /* { dg-bogus "implicit" } */
75   i = (double)f == d;                        /* { dg-bogus "implicit" } */
76   i = d != (double)f;                        /* { dg-bogus "implicit" } */
79 /* There is no warning on conversions that occur in assignment (and
80    assignment-like) contexts.  */
82 void 
83 assignments (void)
85   d = f;           /* { dg-bogus "implicit" } */
86   double_fn (f);   /* { dg-bogus "implicit" } */
87   d = float_fn (); /* { dg-bogus "implicit" } */
90 /* There is no warning in non-evaluated contexts.  */
92 void
93 non_evaluated (void)
95   s = sizeof (f + 1.0);             /* { dg-bogus "implicit" } */
96   s = __alignof__ (f + 1.0);        /* { dg-bogus "implicit" } */
97   d = (__typeof__(f + 1.0))f;       /* { dg-bogus "implicit" } */
98   s = sizeof (i ? f : d);           /* { dg-bogus "implicit" } */