[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / destructor-template.cpp
blob7a3398308bbee6f0399ba81c1a295a48494dd82f
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 template<typename A> class s0 {
4 template<typename B> class s1;
5 };
7 template<typename A>
8 template<typename B>
9 class s0<A>::s1 : s0<A> {
10 ~s1() {}
11 s0<A> ms0;
14 struct Incomplete;
16 template<typename T>
17 void destroy_me(T me) {
18 me.~T();
21 template void destroy_me(Incomplete*);
23 namespace PR6152 {
24 template<typename T> struct X { void f(); };
25 template<typename T> struct Y { };
26 template<typename T>
27 void X<T>::f() {
28 Y<T> *y;
29 y->template Y<T>::~Y();
30 y->template Y<T>::~Y<T>();
31 y->~Y();
34 template struct X<int>;
37 namespace cvquals {
38 template<typename T>
39 void f(int *ptr) {
40 ptr->~T();
43 template void f<const volatile int>(int *);
46 namespace PR7239 {
47 template<class E> class A { };
48 class B {
49 void f() {
50 A<int>* x;
51 x->A<int>::~A<int>();
56 namespace PR7904 {
57 struct Foo {};
58 template <class T>
59 Foo::~Foo() { // expected-error{{destructor cannot be declared as a template}}
60 T t;
61 T &pT = t;
62 pT;
64 Foo f;
67 namespace rdar13140795 {
68 template <class T> class shared_ptr {};
70 template <typename T> struct Marshal {
71 static int gc();
75 template <typename T> int Marshal<T>::gc() {
76 shared_ptr<T> *x;
77 x->template shared_ptr<T>::~shared_ptr();
78 return 0;
81 void test() {
82 Marshal<int>::gc();
86 namespace PR16852 {
87 template<typename T> struct S { int a; T x; };
88 template<typename T> decltype(S<T>().~S()) f(); // expected-note {{candidate template ignored: couldn't infer template argument 'T'}}
89 void g() { f(); } // expected-error {{no matching function for call to 'f'}}
92 class PR33189
94 template <class T>
95 ~PR33189() { } // expected-error{{destructor cannot be declared as a template}}
98 namespace PR38671 {
99 struct S {
100 template <class>
101 ~S(); // expected-error{{destructor cannot be declared as a template}}
103 struct T : S {
104 ~T() = default;
106 } // namespace PR38671