xref: /llvm-project/clang/test/Interpreter/const.cpp (revision ba400539e2880274bde7d70244269a82347dca31)
1c9ab1d89SSean Perry // UNSUPPORTED: system-aix, system-zos
24812eecdSJonas Hahnfeld // see https://github.com/llvm/llvm-project/issues/68092
32c4f938fSMartin Storsjö // XFAIL: host={{.*}}-windows-msvc
44812eecdSJonas Hahnfeld 
5*ba400539SVitaly Buka // The test is flaky with asan https://github.com/llvm/llvm-project/issues/102858.
6*ba400539SVitaly Buka // UNSUPPORTED: asan
7*ba400539SVitaly Buka 
805137ecfSJonas Hahnfeld // RUN: cat %s | clang-repl | FileCheck %s
905137ecfSJonas Hahnfeld // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
1005137ecfSJonas Hahnfeld 
1105137ecfSJonas Hahnfeld extern "C" int printf(const char*, ...);
1205137ecfSJonas Hahnfeld 
1305137ecfSJonas Hahnfeld struct A { int val; A(int v); ~A(); void f() const; };
1405137ecfSJonas Hahnfeld A::A(int v) : val(v) { printf("A(%d), this = %p\n", val, this); }
1505137ecfSJonas Hahnfeld A::~A() { printf("~A, this = %p, val = %d\n", this, val); }
1605137ecfSJonas Hahnfeld void A::f() const { printf("f: this = %p, val = %d\n", this, val); }
1705137ecfSJonas Hahnfeld 
1805137ecfSJonas Hahnfeld const A a(1);
19b6ee41f8SJonas Hahnfeld // CHECK: A(1), this = [[THIS:.+]]
2005137ecfSJonas Hahnfeld // The constructor must only be called once!
2105137ecfSJonas Hahnfeld // CHECK-NOT: A(1)
2205137ecfSJonas Hahnfeld 
2305137ecfSJonas Hahnfeld a.f();
2405137ecfSJonas Hahnfeld // CHECK-NEXT: f: this = [[THIS]], val = 1
2505137ecfSJonas Hahnfeld a.f();
2605137ecfSJonas Hahnfeld // CHECK-NEXT: f: this = [[THIS]], val = 1
2705137ecfSJonas Hahnfeld 
2805137ecfSJonas Hahnfeld %quit
2905137ecfSJonas Hahnfeld // There must still be no other constructor!
3005137ecfSJonas Hahnfeld // CHECK-NOT: A(1)
3105137ecfSJonas Hahnfeld 
3205137ecfSJonas Hahnfeld // At the end, we expect exactly one destructor call
3305137ecfSJonas Hahnfeld // CHECK: ~A
3405137ecfSJonas Hahnfeld // CHECK-SAME: this = [[THIS]], val = 1
3505137ecfSJonas Hahnfeld // CHECK-NOT: ~A
36