35 lines · cpp
1// see https://github.com/llvm/llvm-project/issues/680922// XFAIL: host={{.*}}-windows-msvc3 4// The test is flaky with asan https://github.com/llvm/llvm-project/issues/102858.5// UNSUPPORTED: asan6 7// RUN: cat %s | clang-repl | FileCheck %s8// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s9 10extern "C" int printf(const char*, ...);11 12struct A { int val; A(int v); ~A(); void f() const; };13A::A(int v) : val(v) { printf("A(%d), this = %p\n", val, this); }14A::~A() { printf("~A, this = %p, val = %d\n", this, val); }15void A::f() const { printf("f: this = %p, val = %d\n", this, val); }16 17const A a(1);18// CHECK: A(1), this = [[THIS:.+]]19// The constructor must only be called once!20// CHECK-NOT: A(1)21 22a.f();23// CHECK-NEXT: f: this = [[THIS]], val = 124a.f();25// CHECK-NEXT: f: this = [[THIS]], val = 126 27%quit28// There must still be no other constructor!29// CHECK-NOT: A(1)30 31// At the end, we expect exactly one destructor call32// CHECK: ~A33// CHECK-SAME: this = [[THIS]], val = 134// CHECK-NOT: ~A35