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>
13 #include <o3tl/deleter.hxx>
14 #include <o3tl/sorted_vector.hxx>
26 // expected-error@+1 {{rather use make_shared than constructing from 'int *' [loplugin:makeshared]}}
27 std::shared_ptr
<int> x(new int);
28 // expected-error@+1 {{rather use make_shared [loplugin:makeshared]}}
30 // expected-error@+1 {{rather use make_shared than constructing from 'int *' [loplugin:makeshared]}}
31 x
= std::shared_ptr
<int>(new int);
33 // no warning expected
34 std::shared_ptr
<int> y(new int, o3tl::default_delete
<int>());
35 y
.reset(new int, o3tl::default_delete
<int>());
36 // no warning expected, no public constructor
37 std::shared_ptr
<S1
> z(new S1
);
40 // no warning expected - this constructor takes an initializer-list, which make_shared does not support
41 auto a
= std::shared_ptr
<o3tl::sorted_vector
<int>>(new o3tl::sorted_vector
<int>({ 1, 2 }));
46 // expected-error-re@+1 {{rather use make_shared than constructing from {{.*}}'unique_ptr<int>'{{.*}} [loplugin:makeshared]}}
47 std::shared_ptr
<int> x
= std::make_unique
<int>(1);
48 // expected-error-re@+1 {{rather use make_shared than constructing from {{.*}}'unique_ptr<int>'{{.*}} [loplugin:makeshared]}}
49 x
= std::make_unique
<int>(1);
52 // expected-error-re@+1 {{rather use make_shared than constructing from {{.*}}'unique_ptr<int>'{{.*}} [loplugin:makeshared]}}
53 std::shared_ptr
<int> y(std::make_unique
<int>(1));
56 std::unique_ptr
<int> u1
;
57 // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'std{{.*}}::unique_ptr<int{{.*}}>') [loplugin:makeshared]}}
58 std::shared_ptr
<int> z
= std::move(u1
);
59 // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'std{{.*}}::unique_ptr<int{{.*}}>') [loplugin:makeshared]}}
63 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */