Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-indeterminate1.C

raw
1 // PR c++/96223
2 // { dg-do compile { target c++20 } }
3 // DR 1787 (if an indeterminate value is produced by an evaluation, the
4 // behavior is undefined except in certain cases)
5 // Note that P1331R2 explicitly disallows in a constant evaluation:
6 // - an lvalue-to-rvalue conversion that is applied to an object with
7 // indeterminate value ([basic.indet]).
8
9 #include <cstddef>
10
11 constexpr int
12 fn1 ()
13 {
14 unsigned char foo;
15 unsigned char u = foo; // { dg-error "not usable in a constant expression" }
16 return 0;
17 }
18
19 constexpr int
20 fn2 ()
21 {
22 unsigned char foo;
23 int i = foo; // { dg-error "not usable in a constant expression" }
24 return 0;
25 }
26
27 constexpr int
28 fn3 ()
29 {
30 unsigned char foo;
31 char8_t u = foo; // { dg-error "not usable in a constant expression" }
32 return 0;
33 }
34
35 constexpr int
36 fn4 ()
37 {
38 std::byte foo;
39 std::byte b = foo; // { dg-error "not usable in a constant expression" }
40 return 0;
41 }
42
43 constexpr int w1 = fn1 ();
44 constexpr int w2 = fn2 ();
45 constexpr int w3 = fn3 ();
46 constexpr int w4 = fn4 ();