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/.
10 #include <sal/config.h>
14 #include <vcl/vclptr.hxx>
15 #include <vcl/vclreferencebase.hxx>
17 struct Widget
: public VclReferenceBase
19 VclPtr
<Widget
> mpParent
;
23 // test that we ignore assignments from a member field
26 // test against false+
27 p
= (true) ? mpParent
.get() : nullptr;
35 void dispose() override
38 VclReferenceBase::dispose();
52 // test the variable init detection
55 Widget
* p
= f(); // expected-error {{assigning a returned-by-value VclPtr<T> to a T* variable is dodgy, should be assigned to a VclPtr. If you know that the RHS does not return a newly created T, then add a '.get()' to the RHS [loplugin:vclwidgets]}}
63 // test the assignment detection
68 p
= f(); // expected-error {{assigning a returned-by-value VclPtr<T> to a T* variable is dodgy, should be assigned to a VclPtr. If you know that the RHS does not return a newly created T, then add a '.get()' to the RHS [loplugin:vclwidgets]}}
76 // test against false+
79 T
* get() { return nullptr; }
90 //TODO: one error should be enough here?
91 // expected-error@+2 {{calling delete on instance of VclReferenceBase subclass, must rather call disposeAndClear() [loplugin:vclwidgets]}}
92 // expected-error@+1 {{calling delete on instance of VclPtr, must rather call disposeAndClear() [loplugin:vclwidgets]}}
94 std::atomic
<int *> p2
;
95 // No false positive here:
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */