|
1 | 1 | // RUN: %clang_cc1 -std=c++2a -fsyntax-only -fcxx-exceptions -verify=ref,both %s
|
2 | 2 | // RUN: %clang_cc1 -std=c++2a -fsyntax-only -fcxx-exceptions -verify=expected,both %s -fexperimental-new-constant-interpreter
|
3 | 3 |
|
| 4 | + |
| 5 | +namespace std { |
| 6 | + struct type_info; |
| 7 | + struct destroying_delete_t { |
| 8 | + explicit destroying_delete_t() = default; |
| 9 | + } inline constexpr destroying_delete{}; |
| 10 | + struct nothrow_t { |
| 11 | + explicit nothrow_t() = default; |
| 12 | + } inline constexpr nothrow{}; |
| 13 | + using size_t = decltype(sizeof(0)); |
| 14 | + enum class align_val_t : size_t {}; |
| 15 | +}; |
| 16 | + |
| 17 | +constexpr void *operator new(std::size_t, void *p) { return p; } |
| 18 | +namespace std { |
| 19 | + template<typename T> constexpr T *construct(T *p) { return new (p) T; } |
| 20 | + template<typename T> constexpr void destroy(T *p) { p->~T(); } |
| 21 | +} |
| 22 | + |
4 | 23 | template <unsigned N>
|
5 | 24 | struct S {
|
6 | 25 | S() requires (N==1) = default;
|
@@ -187,3 +206,22 @@ namespace PureVirtual {
|
187 | 206 | struct PureVirtualCall : Abstract { void f(); }; // both-note {{in call to 'Abstract}}
|
188 | 207 | constexpr PureVirtualCall pure_virtual_call; // both-error {{constant expression}} both-note {{in call to 'PureVirtualCall}}
|
189 | 208 | }
|
| 209 | + |
| 210 | +namespace Dtor { |
| 211 | + constexpr bool pseudo(bool read, bool recreate) { |
| 212 | + using T = bool; |
| 213 | + bool b = false; // both-note {{lifetime has already ended}} |
| 214 | + // This evaluates the store to 'b'... |
| 215 | + (b = true).~T(); |
| 216 | + // ... and ends the lifetime of the object. |
| 217 | + return (read |
| 218 | + ? b // both-note {{read of object outside its lifetime}} |
| 219 | + : true) + |
| 220 | + (recreate |
| 221 | + ? (std::construct(&b), true) |
| 222 | + : true); |
| 223 | + } |
| 224 | + static_assert(pseudo(false, false)); // both-error {{constant expression}} both-note {{in call}} |
| 225 | + static_assert(pseudo(true, false)); // both-error {{constant expression}} both-note {{in call}} |
| 226 | + static_assert(pseudo(false, true)); |
| 227 | +} |
0 commit comments