1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <unordered_map>
19 XXX
* m_pbar
; // expected-note {{member is here [loplugin:useuniqueptr]}}
22 delete m_pbar
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
29 char* m_pbar1
; // expected-note {{member is here [loplugin:useuniqueptr]}}
30 char* m_pbar2
; // expected-note {{member is here [loplugin:useuniqueptr]}}
33 delete[] m_pbar1
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
34 delete[] m_pbar2
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
49 int* m_pbar
[10]; // expected-note {{member is here [loplugin:useuniqueptr]}}
52 for (int i
= 0; i
< 10; ++i
)
53 delete m_pbar
[i
]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
57 int* m_pbar
[10]; // expected-note {{member is here [loplugin:useuniqueptr]}}
61 delete p
; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
65 std::array
<int*,10> m_pbar
; // expected-note {{member is here [loplugin:useuniqueptr]}}
69 delete p
; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
73 std::array
<int*,10> m_pbar
; // expected-note {{member is here [loplugin:useuniqueptr]}}
76 for (int i
= 0; i
< 10; ++i
)
77 delete m_pbar
[i
]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
80 // don't warn for maps, MSVC 2015 has problems with mixing std::map/std::unordered_map and std::unique_ptr
82 std::unordered_map
<int, int*> m_pbar
;
90 XXX
* m_pbar1
; // expected-note {{member is here [loplugin:useuniqueptr]}}
91 XXX
* m_pbar2
; // expected-note {{member is here [loplugin:useuniqueptr]}}
94 delete m_pbar1
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
95 delete m_pbar2
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
99 XXX
* m_pbar1
; // expected-note {{member is here [loplugin:useuniqueptr]}}
100 XXX
* m_pbar2
; // expected-note {{member is here [loplugin:useuniqueptr]}}
101 XXX
* m_pbar3
; // expected-note {{member is here [loplugin:useuniqueptr]}}
102 XXX
* m_pbar4
; // expected-note {{member is here [loplugin:useuniqueptr]}}
107 delete m_pbar1
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
109 if (m_pbar2
!= nullptr)
111 delete m_pbar2
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
113 if (m_pbar3
!= nullptr)
114 delete m_pbar3
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
115 if (m_pbar4
!= nullptr)
119 delete m_pbar4
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
123 // no warning expected
128 if (m_pbar1
!= getOther())
133 XXX
* getOther() { return nullptr; }
136 std::vector
<XXX
*> m_pbar1
; // expected-note {{member is here [loplugin:useuniqueptr]}}
139 for (const auto & p
: m_pbar1
)
141 delete p
; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
146 std::array
<int*,10> m_pbar
; // expected-note {{member is here [loplugin:useuniqueptr]}}
151 delete m_pbar
[i
++]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
154 #define DELETEZ( p ) ( delete p,p = NULL )
156 int * m_pbar1
; // expected-note {{member is here [loplugin:useuniqueptr]}}
157 int * m_pbar2
; // expected-note {{member is here [loplugin:useuniqueptr]}}
161 DELETEZ(m_pbar1
); // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
162 DELETEZ(m_pbar2
); // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
165 // check for unconditional inner compound statements
167 int * m_pbar1
; // expected-note {{member is here [loplugin:useuniqueptr]}}
171 delete m_pbar1
; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */