| 1 |
// PR c++/97573 |
| 2 |
// { dg-do compile } |
| 3 |
// No special options. In C++20 (only), we should get the deprecated warnings |
| 4 |
// by default. -Wenum-compare is enabled by default so some of them will be |
| 5 |
// printed even pre-C++20. |
| 6 |
|
| 7 |
enum E1 { e } e1; |
| 8 |
enum E2 { f } e2; |
| 9 |
__extension__ static enum { } u1; |
| 10 |
__extension__ static enum { } u2; |
| 11 |
static double d; |
| 12 |
|
| 13 |
void |
| 14 |
conv () |
| 15 |
{ |
| 16 |
bool b1 = e == e1; |
| 17 |
bool b2 = e == f; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } } |
| 18 |
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 } |
| 19 |
bool b3 = e == 0.0; // { dg-warning "comparison of enumeration type .E1. with floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 20 |
// { dg-error "comparison of enumeration type .E1. with floating-point type .double." "" { target c++26 } .-1 } |
| 21 |
bool b4 = 0.0 == f; // { dg-warning "comparison of floating-point type .double. with enumeration type .E2." "" { target { c++20 && c++23_down } } } |
| 22 |
// { dg-error "comparison of floating-point type .double. with enumeration type .E2." "" { target c++26 } .-1 } |
| 23 |
int n1 = true ? e : f; // { dg-warning "enumerated mismatch" "" { target c++23_down } } |
| 24 |
// { dg-error "enumerated mismatch" "" { target c++26 } .-1 } |
| 25 |
int n2 = true ? e : 0.0; // { dg-warning "conditional expression between" "" { target { c++20 && c++23_down } } } |
| 26 |
// { dg-error "conditional expression between" "" { target c++26 } .-1 } |
| 27 |
} |
| 28 |
|
| 29 |
int |
| 30 |
enum_enum (bool b) |
| 31 |
{ |
| 32 |
int r = 0; |
| 33 |
const E1 e1c = e; |
| 34 |
|
| 35 |
r += e - e; |
| 36 |
r += e - e1; |
| 37 |
r += e - f; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 38 |
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 39 |
r += f - e; // { dg-warning "arithmetic between different enumeration types .E2. and .E1." "" { target { c++20 && c++23_down } } } |
| 40 |
// { dg-error "arithmetic between different enumeration types .E2. and .E1." "" { target c++26 } .-1 } |
| 41 |
r += f + f; |
| 42 |
r += f + e; // { dg-warning "arithmetic between different enumeration types .E2. and .E1." "" { target { c++20 && c++23_down } } } |
| 43 |
// { dg-error "arithmetic between different enumeration types .E2. and .E1." "" { target c++26 } .-1 } |
| 44 |
r += e + f; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 45 |
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 46 |
|
| 47 |
r += e1 - e2; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 48 |
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 49 |
r += e1 - e1c; |
| 50 |
r += e1c - e1; |
| 51 |
|
| 52 |
r += e * f; // { dg-warning "arithmetic between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 53 |
// { dg-error "arithmetic between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 54 |
r += f * e; // { dg-warning "arithmetic between different enumeration types .E2. and .E1." "" { target { c++20 && c++23_down } } } |
| 55 |
// { dg-error "arithmetic between different enumeration types .E2. and .E1." "" { target c++26 } .-1 } |
| 56 |
r += e * e; |
| 57 |
|
| 58 |
r += e1 < e1c; |
| 59 |
r += e < e1; |
| 60 |
r += e1 < e2; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } } |
| 61 |
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 } |
| 62 |
r += e < f; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } } |
| 63 |
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 } |
| 64 |
r += f < e; // { dg-warning "comparison between .enum E2. and .enum E1." "" { target c++23_down } } |
| 65 |
// { dg-error "comparison between .enum E2. and .enum E1." "" { target c++26 } .-1 } |
| 66 |
|
| 67 |
r += e1 == e1c; |
| 68 |
r += e == e1; |
| 69 |
r += e == f; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } } |
| 70 |
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 } |
| 71 |
r += f == e; // { dg-warning "comparison between .enum E2. and .enum E1." "" { target c++23_down } } |
| 72 |
// { dg-error "comparison between .enum E2. and .enum E1." "" { target c++26 } .-1 } |
| 73 |
r += e1 == e2; // { dg-warning "comparison between .enum E1. and .enum E2." "" { target c++23_down } } |
| 74 |
// { dg-error "comparison between .enum E1. and .enum E2." "" { target c++26 } .-1 } |
| 75 |
r += e2 == e1; // { dg-warning "comparison between .enum E2. and .enum E1." "" { target c++23_down } } |
| 76 |
// { dg-error "comparison between .enum E2. and .enum E1." "" { target c++26 } .-1 } |
| 77 |
|
| 78 |
r += b ? e1 : e1c; |
| 79 |
r += b ? e1 : e; |
| 80 |
r += b ? f : e; // { dg-warning "enumerated mismatch in conditional expression: .E2. vs .E1." "" { target c++23_down } } |
| 81 |
// { dg-error "enumerated mismatch in conditional expression: .E2. vs .E1." "" { target c++26 } .-1 } |
| 82 |
r += b ? e1 : e2; // { dg-warning "enumerated mismatch in conditional expression: .E1. vs .E2." "" { target c++23_down } } |
| 83 |
// { dg-error "enumerated mismatch in conditional expression: .E1. vs .E2." "" { target c++26 } .-1 } |
| 84 |
|
| 85 |
r += e | f; // { dg-warning "bitwise operation between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 86 |
// { dg-error "bitwise operation between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 87 |
r += e ^ f; // { dg-warning "bitwise operation between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 88 |
// { dg-error "bitwise operation between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 89 |
r += e & f; // { dg-warning "bitwise operation between different enumeration types .E1. and .E2." "" { target { c++20 && c++23_down } } } |
| 90 |
// { dg-error "bitwise operation between different enumeration types .E1. and .E2." "" { target c++26 } .-1 } |
| 91 |
r += !e; |
| 92 |
r += e1 | e; |
| 93 |
|
| 94 |
r += e << f; |
| 95 |
r += e >> f; |
| 96 |
r += e || f; |
| 97 |
r += e && f; |
| 98 |
e1 = e1c; |
| 99 |
|
| 100 |
// Anonymous enum. |
| 101 |
r += u1 - u1; |
| 102 |
r += u1 + u2; // { dg-warning "arithmetic between different enumeration types" "" { target { c++20 && c++23_down } } } |
| 103 |
// { dg-error "arithmetic between different enumeration types" "" { target c++26 } .-1 } |
| 104 |
r += u1 * u2; // { dg-warning "arithmetic between different enumeration types" "" { target { c++20 && c++23_down } } } |
| 105 |
// { dg-error "arithmetic between different enumeration types" "" { target c++26 } .-1 } |
| 106 |
r += u1 == u2; // { dg-warning "comparison between" "" { target c++23_down } } |
| 107 |
// { dg-error "comparison between" "" { target c++26 } .-1 } |
| 108 |
r += u1 & u2; // { dg-warning "bitwise operation between different enumeration types" "" { target { c++20 && c++23_down } } } |
| 109 |
// { dg-error "bitwise operation between different enumeration types" "" { target c++26 } .-1 } |
| 110 |
|
| 111 |
return r; |
| 112 |
} |
| 113 |
|
| 114 |
double |
| 115 |
enum_float (bool b) |
| 116 |
{ |
| 117 |
double r = 0.0; |
| 118 |
|
| 119 |
r += e1 - d; // { dg-warning "arithmetic between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 120 |
// { dg-error "arithmetic between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 } |
| 121 |
r += d - e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 122 |
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 } |
| 123 |
r += e1 + d; // { dg-warning "arithmetic between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 124 |
// { dg-error "arithmetic between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 } |
| 125 |
r += d + e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 126 |
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 } |
| 127 |
r += e1 * d; // { dg-warning "arithmetic between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 128 |
// { dg-error "arithmetic between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 } |
| 129 |
r += d * e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 130 |
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 } |
| 131 |
r += u1 * d; // { dg-warning "arithmetic between enumeration type" "" { target { c++20 && c++23_down } } } |
| 132 |
// { dg-error "arithmetic between enumeration type" "" { target c++26 } .-1 } |
| 133 |
r += d * u1; // { dg-warning "arithmetic between floating-point type" "" { target { c++20 && c++23_down } } } |
| 134 |
// { dg-error "arithmetic between floating-point type" "" { target c++26 } .-1 } |
| 135 |
|
| 136 |
r += e1 < d; // { dg-warning "comparison of enumeration type .E1. with floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 137 |
// { dg-error "comparison of enumeration type .E1. with floating-point type .double." "" { target c++26 } .-1 } |
| 138 |
r += d < e1; // { dg-warning "comparison of floating-point type .double. with enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 139 |
// { dg-error "comparison of floating-point type .double. with enumeration type .E1." "" { target c++26 } .-1 } |
| 140 |
r += d == e1; // { dg-warning "comparison of floating-point type .double. with enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 141 |
// { dg-error "comparison of floating-point type .double. with enumeration type .E1." "" { target c++26 } .-1 } |
| 142 |
r += e1 == d; // { dg-warning "comparison of enumeration type .E1. with floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 143 |
// { dg-error "comparison of enumeration type .E1. with floating-point type .double." "" { target c++26 } .-1 } |
| 144 |
r += u1 == d; // { dg-warning "comparison of enumeration type" "" { target { c++20 && c++23_down } } } |
| 145 |
// { dg-error "comparison of enumeration type" "" { target c++26 } .-1 } |
| 146 |
r += d == u1; // { dg-warning "comparison of floating-point type" "" { target { c++20 && c++23_down } } } |
| 147 |
// { dg-error "comparison of floating-point type" "" { target c++26 } .-1 } |
| 148 |
|
| 149 |
r += b ? e1 : d; // { dg-warning "conditional expression between enumeration type .E1. and floating-point type .double." "" { target { c++20 && c++23_down } } } |
| 150 |
// { dg-error "conditional expression between enumeration type .E1. and floating-point type .double." "" { target c++26 } .-1 } |
| 151 |
r += b ? d : e1; // { dg-warning "conditional expression between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 152 |
// { dg-error "conditional expression between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 } |
| 153 |
r += b ? d : u1; // { dg-warning "conditional expression between" "" { target { c++20 && c++23_down } } } |
| 154 |
// { dg-error "conditional expression between" "" { target c++26 } .-1 } |
| 155 |
r += b ? u1 : d; // { dg-warning "conditional expression between" "" { target { c++20 && c++23_down } } } |
| 156 |
// { dg-error "conditional expression between" "" { target c++26 } .-1 } |
| 157 |
|
| 158 |
d += e1; // { dg-warning "arithmetic between floating-point type .double. and enumeration type .E1." "" { target { c++20 && c++23_down } } } |
| 159 |
// { dg-error "arithmetic between floating-point type .double. and enumeration type .E1." "" { target c++26 } .-1 } |
| 160 |
d = e1; |
| 161 |
|
| 162 |
return r; |
| 163 |
} |