2018-06-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / Wconversion-complex-gnu.c
blobd4583508d1f45ae75c61ea8759f73c9e2f24f685
1 /* PR c/48956: Test for diagnostics for implicit conversions involving complex
2 types. See also Wconversion-complex-c99.c.
4 These tests cover integer complex values (which are GNU extensions). */
6 /* { dg-do compile } */
7 /* { dg-skip-if "doubles are floats,ints are 16bits" { "avr-*-*" } } */
8 /* { dg-options " -std=gnu99 -Wconversion " } */
9 /* { dg-require-effective-target int32plus } */
10 /* { dg-require-effective-target double64plus } */
12 #include <limits.h>
14 void fsi (int);
15 void fui (unsigned);
16 void ffloat (float);
17 int vsi;
18 unsigned int vui;
19 float vfloat;
21 void fsic (int _Complex);
22 void fuic (unsigned _Complex);
23 void ffloatc (float _Complex);
24 int _Complex vsic;
25 unsigned _Complex vuic;
26 float _Complex vfloatc;
28 /* Check implicit conversions of float complex-domain values to integer
29 complex-domain types. */
30 void
31 var_float_to_int (void)
33 double _Complex doublec = 0.;
35 fsic (doublec); /* { dg-warning "conversion" } */
36 fuic (doublec); /* { dg-warning "conversion" } */
38 vsic = doublec; /* { dg-warning "conversion" } */
39 vuic = doublec; /* { dg-warning "conversion" } */
42 /* Check implicit conversions of integer complex-domain values to integer
43 real-domain types. */
44 void
45 var_complex_to_real (void)
47 int _Complex ic = 0;
48 unsigned _Complex uc = 0;
49 unsigned long long _Complex ullc = 0;
51 fsic (ic);
52 fuic (uc);
53 vsic = ic;
54 vuic = uc;
56 fsi (ic); /* { dg-warning "conversion" } */
57 vsi = ic; /* { dg-warning "conversion" } */
58 fui (uc); /* { dg-warning "conversion" } */
59 vui = uc; /* { dg-warning "conversion" } */
61 fuic (ullc); /* { dg-warning "conversion" } */
62 vuic = ullc; /* { dg-warning "conversion" } */
64 fui (ic); /* { dg-warning "conversion" } */
65 vui = ic; /* { dg-warning "conversion" } */
68 /* Check implicit conversions of float complex-domain constants to integer
69 types. */
70 void
71 const_float_to_int (void)
73 fsic (1. - 1.i);
74 fuic (1. + 1.i);
75 vsic = 1. - 1.i;
76 vuic = 1. + 1.i;
78 fsic (0.5 + 0.i); /* { dg-warning "conversion" } */
79 vsic = 0.5 + 0.i; /* { dg-warning "conversion" } */
80 fuic (0.5 + 0.i); /* { dg-warning "conversion" } */
83 /* Check implicit conversions of integer complex-domain constants to integer
84 types. */
85 void
86 const_complex_int_to_real_int (void)
88 fsi (-1 + 0i);
89 fui (1 + 0i);
90 vsi = -1 + 0i;
91 vui = 1 + 0i;
93 fui (1 + 1i); /* { dg-warning "conversion" } */
94 vui = 1 + 1i; /* { dg-warning "conversion" } */
96 fui (UINT_MAX + 1ull + 0i); /* { dg-warning "conversion" } */
97 vui = UINT_MAX + 1ull + 0i; /* { dg-warning "conversion" } */
99 ffloat (UINT_MAX + 0i); /* { dg-warning "conversion" } */
100 vfloat = UINT_MAX + 0i; /* { dg-warning "conversion" } */
103 void
104 const_complex_int_narrowing (void)
106 fsic (1 - 1i);
107 fuic (1 + 1i);
108 vsic = 1 - 1i;
109 vuic = 1 + 1i;
111 fuic (UINT_MAX + 1ull + 1i); /* { dg-warning "conversion" } */
112 fuic ((UINT_MAX + 1ull) * 1i); /* { dg-warning "conversion" } */
113 fuic ((UINT_MAX + 1ull) + (UINT_MAX + 1ull) * 1i); /* { dg-warning "conversion" } */
115 vuic = (UINT_MAX + 1ull) * 1i; /* { dg-warning "conversion" } */
116 vuic = (UINT_MAX + 1ull) + 1i; /* { dg-warning "conversion" } */
117 vuic = (UINT_MAX + 1ull) + (UINT_MAX + 1ull) * 1i; /* { dg-warning "conversion" } */
119 ffloatc (UINT_MAX * 1i); /* { dg-warning "conversion" } */
120 ffloatc (UINT_MAX + 1i); /* { dg-warning "conversion" } */
121 ffloatc (UINT_MAX + UINT_MAX * 1i); /* { dg-warning "conversion" } */
123 vfloatc = UINT_MAX * 1i; /* { dg-warning "conversion" } */
124 vfloatc = UINT_MAX + 1i; /* { dg-warning "conversion" } */
125 vfloatc = UINT_MAX + UINT_MAX * 1i; /* { dg-warning "conversion" } */