Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / simplifyconstruct.cxx
blobd44738f78d01c9f72f3eaf4a08309ac08792fed7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
10 #include <memory>
11 #include <rtl/ref.hxx>
12 #include <tools/gen.hxx>
14 namespace test1
16 struct Foo
18 void acquire();
19 void release();
21 class Foo1
23 std::unique_ptr<int> m_pbar1;
24 rtl::Reference<Foo> m_pbar2;
25 Foo1()
26 : m_pbar1(nullptr)
27 // expected-error@-1 {{no need to explicitly init an instance of 'std::unique_ptr<int>' with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
28 , m_pbar2(nullptr)
29 // expected-error@-1 {{no need to explicitly init an instance of 'rtl::Reference<Foo>' with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
35 // no warning expected when using std::unique_ptr constructor with a custom deleter
36 namespace test2
38 struct ITypeLib
41 struct IUnknown
43 void Release();
45 void func2()
47 std::unique_ptr<IUnknown, void (*)(IUnknown * p)> aITypeLibGuard(nullptr, [](IUnknown* p) {
48 if (p)
49 p->Release();
50 });
54 namespace test3
56 struct Foo
58 void acquire();
59 void release();
61 void f(Foo* f)
63 // expected-error@+1 {{simplify [loplugin:simplifyconstruct]}}
64 rtl::Reference<Foo> x = rtl::Reference(f);
68 // no warning expected
69 namespace test4
71 struct Foo
73 void acquire();
74 void release();
76 void f(Foo* f) { auto x = rtl::Reference(f); }
79 namespace test5
81 void f()
83 // expected-error@+1 {{simplify [loplugin:simplifyconstruct]}}
84 tools::Rectangle x = tools::Rectangle(10, 10, 10, 10);
85 (void)x;
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */