blob: b59794d2bb8dfdef9105bb5a9c44adf576172a47 (
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// PR c++/97573
// { dg-do compile }
// No special options. In C++20 (only), we should get the deprecated warnings
// by default. -Wenum-compare is enabled by default so some of them will be
// printed even pre-C++20.
enum E1 { e } e1;
enum E2 { f } e2;
__extension__ static enum { } u1;
__extension__ static enum { } u2;
static double d;
void
conv ()
{
bool b1 = e == e1;
bool b2 = e == f; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } }
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 }
bool b3 = e == 0.0; // { dg-warning "comparison of enumeration type .E1. with floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of enumeration type .E1. with floating-point type .double." "" { target c++26 } .-1 }
bool b4 = 0.0 == f; // { dg-warning "comparison of floating-point type .double. with enumeration type .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of floating-point type .double. with enumeration type .E2." "" { target c++26 } .-1 }
int n1 = true ? e : f; // { dg-warning "enumerated mismatch" "" { target c++23_down } }
// { dg-error "enumerated mismatch" "" { target c++26 } .-1 }
int n2 = true ? e : 0.0; // { dg-warning "conditional expression between" "" { target { c++20 && c++23_down } } }
// { dg-error "conditional expression between" "" { target c++26 } .-1 }
}
int
enum_enum (bool b)
{
int r = 0;
const E1 e1c = e;
r += e - e;
r += e - e1;
r += e - f; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += f - e; // { dg-warning "arithmetic between different enumeration types .E2. and .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E2. and .E1." "" { target c++26 } .-1 }
r += f + f;
r += f + e; // { dg-warning "arithmetic between different enumeration types .E2. and .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E2. and .E1." "" { target c++26 } .-1 }
r += e + f; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += e1 - e2; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += e1 - e1c;
r += e1c - e1;
r += e * f; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += f * e; // { dg-warning "arithmetic between different enumeration types .E2. and .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types .E2. and .E1." "" { target c++26 } .-1 }
r += e * e;
r += e1 < e1c;
r += e < e1;
r += e1 < e2; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } }
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 }
r += e < f; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } }
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 }
r += f < e; // { dg-warning "comparison between .enum E2. and .enum E1." "" { target c++23_down } }
// { dg-error "comparison between .enum E2. and .enum E1." "" { target c++26 } .-1 }
r += e1 == e1c;
r += e == e1;
r += e == f; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } }
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 }
r += f == e; // { dg-warning "comparison between .enum E2. and .enum E1." "" { target c++23_down } }
// { dg-error "comparison between .enum E2. and .enum E1." "" { target c++26 } .-1 }
r += e1 == e2; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } }
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 }
r += e2 == e1; // { dg-warning "comparison between .enum E2. and .enum E1." "" { target c++23_down } }
// { dg-error "comparison between .enum E2. and .enum E1." "" { target c++26 } .-1 }
r += b ? e1 : e1c;
r += b ? e1 : e;
r += b ? f : e; // { dg-warning "enumerated mismatch in conditional expression: .E2. vs .E1." "" { target c++23_down } }
// { dg-error "enumerated mismatch in conditional expression: .E2. vs .E1." "" { target c++26 } .-1 }
r += b ? e1 : e2; // { dg-warning "enumerated mismatch in conditional expression: .E1. vs .E2." "" { target c++23_down } }
// { dg-error "enumerated mismatch in conditional expression: .E1. vs .E2." "" { target c++26 } .-1 }
r += e | f; // { dg-warning "bitwise operation between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "bitwise operation between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += e ^ f; // { dg-warning "bitwise operation between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "bitwise operation between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += e & f; // { dg-warning "bitwise operation between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } }
// { dg-error "bitwise operation between different enumeration types .E1. and .E2." "" { target c++26 } .-1 }
r += !e;
r += e1 | e;
r += e << f;
r += e >> f;
r += e || f;
r += e && f;
e1 = e1c;
// Anonymous enum.
r += u1 - u1;
r += u1 + u2; // { dg-warning "arithmetic between different enumeration types" "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types" "" { target c++26 } .-1 }
r += u1 * u2; // { dg-warning "arithmetic between different enumeration types" "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between different enumeration types" "" { target c++26 } .-1 }
r += u1 == u2; // { dg-warning "comparison between" "" { target c++23_down } }
// { dg-error "comparison between" "" { target c++26 } .-1 }
r += u1 & u2; // { dg-warning "bitwise operation between different enumeration types" "" { target { c++20 && c++23_down } } }
// { dg-error "bitwise operation between different enumeration types" "" { target c++26 } .-1 }
return r;
}
double
enum_float (bool b)
{
double r = 0.0;
r += e1 - d; // { dg-warning "arithmetic between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 }
r += d - e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 }
r += e1 + d; // { dg-warning "arithmetic between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 }
r += d + e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 }
r += e1 * d; // { dg-warning "arithmetic between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 }
r += d * e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 }
r += u1 * d; // { dg-warning "arithmetic between enumeration type" "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between enumeration type" "" { target c++26 } .-1 }
r += d * u1; // { dg-warning "arithmetic between floating-point type" "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between floating-point type" "" { target c++26 } .-1 }
r += e1 < d; // { dg-warning "comparison of enumeration type .E1. with floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of enumeration type .E1. with floating-point type .double." "" { target c++26 } .-1 }
r += d < e1; // { dg-warning "comparison of floating-point type .double. with enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of floating-point type .double. with enumeration type .E1." "" { target c++26 } .-1 }
r += d == e1; // { dg-warning "comparison of floating-point type .double. with enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of floating-point type .double. with enumeration type .E1." "" { target c++26 } .-1 }
r += e1 == d; // { dg-warning "comparison of enumeration type .E1. with floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of enumeration type .E1. with floating-point type .double." "" { target c++26 } .-1 }
r += u1 == d; // { dg-warning "comparison of enumeration type" "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of enumeration type" "" { target c++26 } .-1 }
r += d == u1; // { dg-warning "comparison of floating-point type" "" { target { c++20 && c++23_down } } }
// { dg-error "comparison of floating-point type" "" { target c++26 } .-1 }
r += b ? e1 : d; // { dg-warning "conditional expression between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } }
// { dg-error "conditional expression between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 }
r += b ? d : e1; // { dg-warning "conditional expression between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "conditional expression between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 }
r += b ? d : u1; // { dg-warning "conditional expression between" "" { target { c++20 && c++23_down } } }
// { dg-error "conditional expression between" "" { target c++26 } .-1 }
r += b ? u1 : d; // { dg-warning "conditional expression between" "" { target { c++20 && c++23_down } } }
// { dg-error "conditional expression between" "" { target c++26 } .-1 }
d += e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } }
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 }
d = e1;
return r;
}
|