Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / noexceptmove.cxx
blobc0742c8284b7dca54bd5d54ac31af6c4b5c86cf4
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 namespace test1
12 class Mapping
14 char* m_pMapping;
16 // expected-error@+1 {{move constructor can be noexcept [loplugin:noexceptmove]}}
17 Mapping(Mapping&& other)
18 : m_pMapping(other.m_pMapping)
20 other.m_pMapping = nullptr;
23 // expected-error@+1 {{move operator= can be noexcept [loplugin:noexceptmove]}}
24 Mapping& operator=(Mapping&& other)
26 m_pMapping = other.m_pMapping;
27 other.m_pMapping = nullptr;
28 return *this;
33 // No warning expected, because calling throwing function.
34 namespace test2
36 void foo() noexcept(false);
38 class Bar
40 Bar(Bar&&) { foo(); }
44 // no warning expected, because calling throwing constructor
45 namespace test3
47 struct Foo
49 Foo() noexcept(false);
51 class Bar
53 Bar(Bar&&) { Foo aFoo; }
56 class Bar2
58 Foo m_foo;
60 Bar2(Bar2&&) {}
64 // No warning expected, because calling throwing destructor.
65 namespace test4
67 struct Foo
69 ~Foo() noexcept(false);
72 class Bar
74 Bar(Bar&&) { Foo aFoo; }
78 // Check for calls to defaulted constructors.
79 namespace test5
81 struct Foo
83 Foo() = default; // non-throwing
85 class Bar
87 Bar(Bar&&) // expected-error {{move constructor can be noexcept [loplugin:noexceptmove]}}
89 Foo aFoo;
90 (void)aFoo;
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */