1 // P2280R4 - Using unknown pointers and references in constant expressions
3 // { dg-do compile { target c++20 } }
7 using size_t = decltype(sizeof(42));
9 template <typename T, size_t N>
10 constexpr size_t array_size(T (&)[N]) {
14 void use_array(int const (&gold_medal_mel)[2]) {
15 constexpr auto gold = array_size(gold_medal_mel); // OK
18 constexpr auto olympic_mile() {
19 const int ledecky = 1500;
20 return []{ return ledecky; };
22 static_assert(olympic_mile()() == 1500); // OK
25 constexpr int phelps() { return 28; }
26 virtual constexpr int lochte() { return 12; }
30 constexpr int how_many(Swim& swam) {
32 return (p + 1 - 1)->phelps();
35 void splash(Swim& swam) {
36 static_assert(swam.phelps() == 28); // OK
37 static_assert((&swam)->phelps() == 28); // OK
40 static_assert(pswam->phelps() == 28); // { dg-error "non-constant|not usable" }
42 static_assert(how_many(swam) == 28); // OK
43 static_assert(Swim().lochte() == 12); // OK
45 static_assert(swam.lochte() == 12); // { dg-error "non-constant|not a constant" }
47 static_assert(swam.coughlin == 12); // { dg-error "non-constant|not a constant" }
53 constexpr auto& sandeno = typeid(dc); // OK, can only be typeid(Swim)
54 constexpr auto& gallagher = typeid(trident); // { dg-error "not a constant" }