bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / test / simplifyconstruct.cxx
blob8fbffc8ba2d7ed94038926cacd3b4e2182eff058
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>
13 namespace test1
15 struct Foo
17 void acquire();
18 void release();
20 class Foo1
22 std::unique_ptr<int> m_pbar1;
23 rtl::Reference<Foo> m_pbar2;
24 Foo1()
25 : m_pbar1(nullptr)
26 // expected-error@-1 {{no need to explicitly init an instance of 'std::unique_ptr<int>' with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
27 , m_pbar2(nullptr)
28 // expected-error@-1 {{no need to explicitly init an instance of 'rtl::Reference<Foo>' with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
34 // no warning expected when using std::unique_ptr constructor with a custom deleter
35 namespace test2
37 struct ITypeLib
40 struct IUnknown
42 void Release();
44 void func2()
46 std::unique_ptr<IUnknown, void (*)(IUnknown * p)> aITypeLibGuard(nullptr, [](IUnknown* p) {
47 if (p)
48 p->Release();
49 });
53 namespace test3
55 struct Foo
57 void acquire();
58 void release();
60 void f(Foo* f)
62 // expected-error@+1 {{simplify [loplugin:simplifyconstruct]}}
63 rtl::Reference<Foo> x = rtl::Reference(f);
67 // no warning expected
68 namespace test4
70 struct Foo
72 void acquire();
73 void release();
75 void f(Foo* f) { auto x = rtl::Reference(f); }
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */