teak-llvm/clang/test/SemaCXX/warn-exit-time-destructors.cpp
Erik Pilkington 5a559e64a9 Add a new flag and attributes to control static destructor registration
This commit adds the flag -fno-c++-static-destructors and the attributes
[[clang::no_destroy]] and [[clang::always_destroy]]. no_destroy specifies that a
specific static or thread duration variable shouldn't have it's destructor
registered, and is the default in -fno-c++-static-destructors mode.
always_destroy is the opposite, and is the default in -fc++-static-destructors
mode.

A variable whose destructor is disabled (either because of
-fno-c++-static-destructors or [[clang::no_destroy]]) doesn't count as a use of
the destructor, so we don't do any access checking or mark it referenced. We
also don't emit -Wexit-time-destructors for these variables.

rdar://21734598

Differential revision: https://reviews.llvm.org/D50994

llvm-svn: 340306
2018-08-21 17:24:06 +00:00

51 lines
1.1 KiB
C++

// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify
namespace test1 {
struct A { ~A(); };
A a; // expected-warning {{declaration requires an exit-time destructor}}
A b[10]; // expected-warning {{declaration requires an exit-time destructor}}
A c[10][10]; // expected-warning {{declaration requires an exit-time destructor}}
A &d = a;
A &e = b[5];
A &f = c[5][7];
}
namespace test2 {
void f() {
struct A { ~A() { } };
static A a; // expected-warning {{declaration requires an exit-time destructor}}
static A b[10]; // expected-warning {{declaration requires an exit-time destructor}}
static A c[10][10]; // expected-warning {{declaration requires an exit-time destructor}}
static A &d = a;
static A &e = b[5];
static A &f = c[5][7];
}
}
namespace test3 {
struct A { ~A() = default; };
A a;
struct B { ~B(); };
struct C : B { ~C() = default; };
C c; // expected-warning {{exit-time destructor}}
class D {
friend struct E;
~D() = default;
};
struct E : D {
D d;
~E() = default;
};
E e;
}
namespace test4 {
struct A { ~A(); };
[[clang::no_destroy]] A a; // no warning
}