| 1 |
// P0784R7 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
namespace std |
| 5 |
{ |
| 6 |
typedef __SIZE_TYPE__ size_t; |
| 7 |
} |
| 8 |
|
| 9 |
inline void *operator new (std::size_t, void *p) noexcept |
| 10 |
{ return p; } |
| 11 |
void *operator new (std::size_t) noexcept; |
| 12 |
|
| 13 |
constexpr bool |
| 14 |
foo () |
| 15 |
{ |
| 16 |
auto p = static_cast<int *> (::operator new (sizeof (int))); // { dg-error "call to non-'constexpr' function" "" { target c++20_down } } |
| 17 |
*p = 1; |
| 18 |
::operator delete (p); |
| 19 |
return false; |
| 20 |
} |
| 21 |
|
| 22 |
struct S { constexpr S () : s (0) {} int s; }; |
| 23 |
|
| 24 |
constexpr bool |
| 25 |
bar () |
| 26 |
{ |
| 27 |
auto p = static_cast<S *> (::operator new (sizeof (S))); // { dg-error "call to non-'constexpr' function" "" { target c++20_down } } |
| 28 |
auto q = new (p) S (); |
| 29 |
q->s++; |
| 30 |
q->~S (); |
| 31 |
::operator delete (p); |
| 32 |
return false; |
| 33 |
} |