Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/enum-conv1.C

raw
1 // P2864R2 - Remove Deprecated Arithmetic Conversion on Enumerations From C++26
2 // { dg-do compile { target c++20 } }
3
4 enum A { a };
5 enum B { b };
6
7 template <auto X, auto Y> decltype (true ? X : Y) f1 () { throw 1; }
8 // { dg-error "enumerated mismatch in conditional expression: 'A' vs 'B'" "" { target c++26 } .-1 }
9 // { dg-error "conditional expression between enumeration type 'A' and floating-point type 'double'" "" { target c++26 } .-2 }
10 // { dg-error "conditional expression between floating-point type 'double' and enumeration type 'A'" "" { target c++26 } .-3 }
11 template <auto X, auto Y> decltype (X + Y) f2 () { throw 1; }
12 // { dg-error "arithmetic between different enumeration types 'A' and 'B'" "" { target c++26 } .-1 }
13 // { dg-error "arithmetic between enumeration type 'A' and floating-point type 'double'" "" { target c++26 } .-2 }
14 // { dg-error "arithmetic between floating-point type 'double' and enumeration type 'A'" "" { target c++26 } .-3 }
15 template <auto X, auto Y> decltype (X | Y) f3 () { throw 1; }
16 // { dg-error "bitwise operation between different enumeration types 'A' and 'B'" "" { target c++26 } .-1 }
17 template <auto X, auto Y> decltype (X < Y) f4 () { throw 1; }
18 // { dg-error "comparison between 'enum A' and 'enum B'" "" { target c++26 } .-1 }
19 // { dg-error "comparison of enumeration type 'A' with floating-point type 'double'" "" { target c++26 } .-2 }
20 // { dg-error "comparison of floating-point type 'double' with enumeration type 'A'" "" { target c++26 } .-3 }
21
22 int
23 main ()
24 {
25 f1<a, a> ();
26 f2<a, a> ();
27 f3<b, b> ();
28 f4<b, b> ();
29 f1<a, b> (); // { dg-error "no matching function for call to" "" { target c++26 } }
30 f2<a, b> (); // { dg-error "no matching function for call to" "" { target c++26 } }
31 f3<a, b> (); // { dg-error "no matching function for call to" "" { target c++26 } }
32 f4<a, b> (); // { dg-error "no matching function for call to" "" { target c++26 } }
33 f1<a, 0.0> (); // { dg-error "no matching function for call to" "" { target c++26 } }
34 f2<a, 0.0> (); // { dg-error "no matching function for call to" "" { target c++26 } }
35 f4<a, 0.0> (); // { dg-error "no matching function for call to" "" { target c++26 } }
36 f1<0.0, a> (); // { dg-error "no matching function for call to" "" { target c++26 } }
37 f2<0.0, a> (); // { dg-error "no matching function for call to" "" { target c++26 } }
38 f4<0.0, a> (); // { dg-error "no matching function for call to" "" { target c++26 } }
39 }