Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / simplifypointertobool.cxx
blob2980003e19c7bddae9f1e57c7869ff99aea0e1aa
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 "com/sun/star/uno/XInterface.hpp"
13 void foo();
15 bool test1(std::unique_ptr<int> p2)
17 // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}}
18 if (p2.get())
19 foo();
20 // expected-error@+1 {{simplify, drop the get() and wrap the expression in a functional cast to bool [loplugin:simplifypointertobool]}}
21 bool b1 = p2.get();
22 // expected-error@+3 {{simplify, drop the get() and turn the surrounding parentheses into a functional cast to bool [loplugin:simplifypointertobool]}}
23 // expected-note@+1 {{surrounding parentheses here [loplugin:simplifypointertobool]}}
24 bool b2 = ( // deliberately spread across multiple lines
25 p2.get());
26 return b1 && b2;
29 void test2(std::shared_ptr<int> p)
31 // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}}
32 if (p.get())
33 foo();
34 // expected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}}
35 if (p.get() == nullptr)
36 foo();
37 // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}}
38 if (p == nullptr)
39 foo();
40 // TODOexpected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}}
41 if (p != nullptr)
42 foo();
43 // expected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}}
44 if (nullptr == p.get())
45 foo();
46 // expected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}}
47 if (p.get() != nullptr)
48 foo();
49 // expected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}}
50 if (nullptr != p.get())
51 foo();
54 void test2(int* p)
56 // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}}
57 if (p == nullptr)
58 foo();
59 // TODOexpected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}}
60 if (p != nullptr)
61 foo();
64 void test2(css::uno::Reference<css::uno::XInterface> const& p)
66 // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}}
67 if (p.get())
68 foo();
69 // expected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}}
70 if (p.get() == nullptr)
71 foo();
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */