| 1 |
// see https://github.com/llvm/llvm-project/issues/68092 |
| 2 |
// XFAIL: host={{.*}}-windows-msvc |
| 3 |
|
| 4 |
// The test is flaky with asan https://github.com/llvm/llvm-project/issues/102858. |
| 5 |
// UNSUPPORTED: asan |
| 6 |
|
| 7 |
// RUN: cat %s | clang-repl | FileCheck %s |
| 8 |
// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s |
| 9 |
|
| 10 |
extern "C" int printf(const char*, ...); |
| 11 |
|
| 12 |
struct A { int val; A(int v); ~A(); void f() const; }; |
| 13 |
A::A(int v) : val(v) { printf("A(%d), this = %p\n", val, this); } |
| 14 |
A::~A() { printf("~A, this = %p, val = %d\n", this, val); } |
| 15 |
void A::f() const { printf("f: this = %p, val = %d\n", this, val); } |
| 16 |
|
| 17 |
const A a(1); |
| 18 |
// CHECK: A(1), this = [[THIS:.+]] |
| 19 |
// The constructor must only be called once! |
| 20 |
// CHECK-NOT: A(1) |
| 21 |
|
| 22 |
a.f(); |
| 23 |
// CHECK-NEXT: f: this = [[THIS]], val = 1 |
| 24 |
a.f(); |
| 25 |
// CHECK-NEXT: f: this = [[THIS]], val = 1 |
| 26 |
|
| 27 |
%quit |
| 28 |
// There must still be no other constructor! |
| 29 |
// CHECK-NOT: A(1) |
| 30 |
|
| 31 |
// At the end, we expect exactly one destructor call |
| 32 |
// CHECK: ~A |
| 33 |
// CHECK-SAME: this = [[THIS]], val = 1 |
| 34 |
// CHECK-NOT: ~A |