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