Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / consteval-cleanup.cpp
blob499c45db5017702e28746d49e1a6a508a66de7f3
1 // RUN: %clang_cc1 -fblocks -Wno-unused-value -std=c++20 -ast-dump -verify %s -ast-dump | FileCheck %s
3 // expected-no-diagnostics
5 struct P {
6 consteval P() {}
7 };
9 struct A {
10 A(int v) { this->data = new int(v); }
11 const int& get() const {
12 return *this->data;
14 ~A() { delete data; }
15 private:
16 int *data;
19 void foo() {
20 for (;A(1), P(), false;);
21 // CHECK: foo
22 // CHECK: ExprWithCleanups
23 // CHECK-NEXT: BinaryOperator {{.*}} 'bool' ','
24 // CHECK-NEXT: BinaryOperator {{.*}} 'P' ','
25 // CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'A'
26 // CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'A'
27 // CHECK-NEXT: CXXConstructExpr {{.*}} 'A'
28 // CHECK: ConstantExpr {{.*}} 'P'
29 // CHECK-NEXT: value:
30 // CHECK-NEXT: ExprWithCleanups
33 void foobar() {
34 A a(1);
35 for (; ^{ auto ptr = &a.get(); }(), P(), false;);
36 // CHECK: ExprWithCleanups
37 // CHECK-NEXT: cleanup Block
38 // CHECK-NEXT: BinaryOperator {{.*}} 'bool' ','
39 // CHECK-NEXT: BinaryOperator {{.*}} 'P' ','
40 // CHECK-NEXT: CallExpr
41 // CHECK-NEXT: BlockExpr
42 // CHECK: ConstantExpr {{.*}} 'P'
43 // CHECK-NEXT: value:
44 // CHECK-NEXT: ExprWithCleanups
45 // CHECK-NOT: cleanup Block
48 struct B {
49 int *p = new int(38);
50 consteval int get() { return *p; }
51 constexpr ~B() { delete p; }
54 void bar() {
55 // CHECK: bar
56 // CHECK: ExprWithCleanups
57 // CHECK: ConstantExpr
58 // CHECK-NEXT: value:
59 // CHECK-NEXT: ExprWithCleanups
60 int k = B().get();