Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-exit-time-destructors.cpp
blob2f14243cb48c470ad86a2124eda1c7e37c09d598
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify=expected,cxx11
2 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wexit-time-destructors %s -verify=expected
4 namespace test1 {
5 struct A { ~A(); };
6 A a; // expected-warning {{declaration requires an exit-time destructor}}
7 A b[10]; // expected-warning {{declaration requires an exit-time destructor}}
8 A c[10][10]; // expected-warning {{declaration requires an exit-time destructor}}
10 A &d = a;
11 A &e = b[5];
12 A &f = c[5][7];
15 namespace test2 {
16 void f() {
17 struct A { ~A() { } };
19 static A a; // expected-warning {{declaration requires an exit-time destructor}}
20 static A b[10]; // expected-warning {{declaration requires an exit-time destructor}}
21 static A c[10][10]; // expected-warning {{declaration requires an exit-time destructor}}
23 static A &d = a;
24 static A &e = b[5];
25 static A &f = c[5][7];
29 namespace test3 {
30 struct A { ~A() = default; };
31 A a;
33 struct B { ~B(); };
34 struct C : B { ~C() = default; };
35 C c; // expected-warning {{exit-time destructor}}
37 class D {
38 friend struct E;
39 ~D() = default;
41 struct E : D {
42 D d;
43 ~E() = default;
45 E e;
48 namespace test4 {
49 struct A { ~A(); };
50 [[clang::no_destroy]] A a; // no warning
53 namespace test5 {
54 #if __cplusplus >= 202002L
55 #define CPP20_CONSTEXPR constexpr
56 #else
57 #define CPP20_CONSTEXPR
58 #endif
59 struct S {
60 CPP20_CONSTEXPR ~S() {}
62 S s; // cxx11-warning {{exit-time destructor}}
64 struct T {
65 CPP20_CONSTEXPR ~T() { if (b) {} }
66 bool b;
68 T t; // expected-warning {{exit-time destructor}}
69 #undef CPP20_CONSTEXPR