bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / test / unusedenumconstants.cxx
blob9f16c981acdec9ade52676e01650167ad69e9f0d
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 <o3tl/typed_flags_set.hxx>
12 namespace test1
14 void test1()
16 enum NameClashMode
18 NONE,
19 NO_CLASH // expected-error {{write NO_CLASH [loplugin:unusedenumconstants]}}
21 NameClashMode eNameClashMode = NO_CLASH;
22 (void)eNameClashMode;
26 enum class BrowseMode
28 Modules = 0x01, // expected-error {{read Modules [loplugin:unusedenumconstants]}}
29 Top = 0x02, // expected-error {{write Top [loplugin:unusedenumconstants]}}
30 Bottom = 0x04, // expected-error {{read Bottom [loplugin:unusedenumconstants]}}
31 Left = 0x04, // expected-error {{write Left [loplugin:unusedenumconstants]}}
33 namespace o3tl
35 template <> struct typed_flags<BrowseMode> : is_typed_flags<BrowseMode, 0xf>
39 BrowseMode g_flags;
40 int test2(BrowseMode nMode)
42 if (nMode & BrowseMode::Modules)
43 return 1;
44 g_flags |= BrowseMode::Top;
45 return 0;
47 bool test2b(BrowseMode nMode) { return bool(nMode & BrowseMode::Bottom); }
48 BrowseMode test2c() { return BrowseMode::Left; }
50 enum class Enum3
52 One = 0x01, // expected-error {{write One [loplugin:unusedenumconstants]}}
53 Two = 0x02 // expected-error {{write Two [loplugin:unusedenumconstants]}}
55 namespace o3tl
57 template <> struct typed_flags<Enum3> : is_typed_flags<Enum3, 0x3>
61 void test3_foo(Enum3);
62 void test3() { test3_foo(Enum3::One | Enum3::Two); }
64 namespace test4
66 enum Enum4
68 ONE, // expected-error {{write ONE [loplugin:unusedenumconstants]}}
69 TWO
71 struct Test4Base
73 Test4Base(Enum4) {}
75 struct Test4 : public Test4Base
77 Test4()
78 : Test4Base(Enum4::ONE)
84 //-----------------------------------------------------------------------------------
86 // check that conditional operator walks up the tree
87 namespace test5
89 enum Enum
91 ONE, // expected-error {{write ONE [loplugin:unusedenumconstants]}}
92 TWO // expected-error {{write TWO [loplugin:unusedenumconstants]}}
95 Enum foo(int x) { return x == 1 ? Enum::ONE : Enum::TWO; }
98 //-----------------------------------------------------------------------------------
99 // Ignore a common pattern that does not introduce any new information, merely removes
100 // information.
101 enum class Enum6
103 Modules = 0x01, // expected-error {{write Modules [loplugin:unusedenumconstants]}}
104 Top = 0x02,
106 namespace o3tl
108 template <> struct typed_flags<Enum6> : is_typed_flags<Enum6, 0x03>
112 void test6()
114 Enum6 foo = Enum6::Modules;
115 foo &= ~Enum6::Top;
116 foo &= (~Enum6::Top);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */