Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/constexpr-nonlit12.C

raw
1 // PR c++/106649
2 // P2448 - Relaxing some constexpr restrictions
3 // { dg-do compile { target c++23 } }
4 // Test that we get a diagnostic even in C++23 if you do call the function.
5
6 constexpr unsigned int
7 fn0 (const int *p)
8 {
9 return *reinterpret_cast<unsigned const int *>(p); // { dg-error ".reinterpret_cast. is not a constant expression" }
10 }
11
12 constexpr void *
13 fn1 (int i)
14 {
15 return (void *) 1LL; // { dg-error ".reinterpret_cast." }
16 }
17
18 void
19 g ()
20 {
21 constexpr int i = 42;
22 constexpr auto a1 = fn0 (&i); // { dg-error "called in a constant expression" }
23 constexpr auto a2 = fn1 (i); // { dg-error "called in a constant expression" }
24 }