2018-01-24 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / Wconversion-complex-c99.c
blobe8bc9db237d10d32e5e596dc2031f04808753519
1 /* PR c/48956: Test for diagnostics for implicit conversions from complex
2 to real types and narrowing conversions of complex types. */
4 /* Architecture restrictions taken from Wconversion-real-integer.c.
5 Likewise, the magic value 16777217. */
7 /* { dg-do compile } */
8 /* { dg-skip-if "doubles are floats,ints are 16bits" { "avr-*-*" } } */
9 /* { dg-options " -std=c99 -pedantic -Wconversion " } */
10 /* { dg-require-effective-target int32plus } */
11 /* { dg-require-effective-target double64plus } */
13 /* A number which does not fit into float. */
14 #define MAX_FLOAT_PLUS 16777217.
16 /* Other types could be added, but that won't affect test coverage. */
17 void ffloatc (float _Complex);
18 void fdoublec (double _Complex);
20 void ffloat (float);
21 void fdouble (double);
23 void fsi (int);
24 void fui (unsigned);
26 float _Complex vfloatc;
27 double _Complex vdoublec;
29 float vfloat;
30 double vdouble;
32 int vsi;
33 unsigned vui;
35 /* Check implicit conversions of complex values to reals. */
36 void
37 var_complex_to_real (void)
39 float _Complex floatc = 0.;
40 double _Complex doublec = 0.;
42 ffloatc (floatc);
43 fdoublec (doublec);
44 vfloatc = floatc;
45 vdoublec = doublec;
47 ffloat (floatc); /* { dg-warning "conversion" } */
48 fdouble (floatc); /* { dg-warning "conversion" } */
49 vfloat = floatc; /* { dg-warning "conversion" } */
50 vdouble = floatc; /* { dg-warning "conversion" } */
52 ffloat (doublec); /* { dg-warning "conversion" } */
53 fdouble (doublec); /* { dg-warning "conversion" } */
54 vfloat = doublec; /* { dg-warning "conversion" } */
55 vdouble = doublec; /* { dg-warning "conversion" } */
58 /* Check implicit narrowing conversions of complex values. */
59 void
60 var_complex_narrowing (void)
62 float _Complex floatc = 0.;
63 double _Complex doublec = 0.;
65 vdoublec = floatc;
66 vfloatc = doublec; /* { dg-warning "conversion from .complex double. to .complex float. may change value" } */
68 fdoublec (floatc);
69 ffloatc (doublec); /* { dg-warning "conversion from .complex double. to .complex float. may change value" } */
72 /* Check implicit conversions of complex values to integers. */
73 void
74 var_complex_to_int (void)
76 float _Complex floatc = 0.;
77 double _Complex doublec = 0.;
79 fsi (floatc); /* { dg-warning "conversion" } */
80 fui (floatc); /* { dg-warning "conversion" } */
81 vsi = floatc; /* { dg-warning "conversion" } */
82 vui = floatc; /* { dg-warning "conversion" } */
84 fsi (doublec); /* { dg-warning "conversion" } */
85 fui (doublec); /* { dg-warning "conversion" } */
86 vsi = doublec; /* { dg-warning "conversion" } */
87 vui = doublec; /* { dg-warning "conversion" } */
90 /* Check implicit conversion of constant complex values to floats. */
91 void
92 const_complex_to_real (void)
94 ffloat (__builtin_complex (0., 1.)); /* { dg-warning "conversion" } */
95 fdouble (__builtin_complex (0., 1.)); /* { dg-warning "conversion" } */
97 vfloat = __builtin_complex (0., 1.); /* { dg-warning "conversion" } */
98 vdouble = __builtin_complex (0., 1.); /* { dg-warning "conversion" } */
100 vfloat = __builtin_complex (1., 0.) + __builtin_complex (1., 0.);
101 vdouble = __builtin_complex (0., 0.) * __builtin_complex (1., 1.);
102 ffloat (__builtin_complex (1., 0.) + __builtin_complex (1., 0.));
103 fdouble (__builtin_complex (1., 0.) + __builtin_complex (1., 0.));
105 vfloat = __builtin_complex (MAX_FLOAT_PLUS, 0.); /* { dg-warning "float-conversion" } */
106 ffloat (__builtin_complex (MAX_FLOAT_PLUS, 0.)); /* { dg-warning "float-conversion" } */
109 /* Check implicit conversion of constant complex values to integers. */
110 void
111 const_complex_to_int (void)
113 vsi = __builtin_complex (-1., 0.);
114 vui = __builtin_complex (1., 0.);
115 fsi (__builtin_complex (-1., 0.));
116 fui (__builtin_complex (1., 0.));
118 vui = __builtin_complex (-1., 0.); /* { dg-warning "overflow" } */
119 fui (__builtin_complex (-1., 0.)); /* { dg-warning "overflow" } */
121 vsi = __builtin_complex (0.5, 0.); /* { dg-warning "float-conversion" } */
122 fui (__builtin_complex (0.5, 0.)); /* { dg-warning "float-conversion" } */
124 vsi = __builtin_complex (-0.5, 0.); /* { dg-warning "float-conversion" } */
125 fui (__builtin_complex (-0.5, 0.)); /* { dg-warning "float-conversion" } */
128 /* Check implicit narrowing conversion of constant complex values to. */
129 void
130 const_complex_narrowing (void)
132 ffloatc (__builtin_complex (-100., 100.));
134 ffloatc (__builtin_complex (MAX_FLOAT_PLUS, 0.)); /* { dg-warning "float-conversion" } */
135 ffloatc (__builtin_complex (0., MAX_FLOAT_PLUS)); /* { dg-warning "float-conversion" } */
136 ffloatc (__builtin_complex (MAX_FLOAT_PLUS, MAX_FLOAT_PLUS)); /* { dg-warning "float-conversion" } */