Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / test / expressionalwayszero.cxx
blob4986e5d690f77580522ecd9dfadeaf26549303de
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 constexpr auto ONE = 1;
13 constexpr auto TWO = 2;
15 enum class Enum1 {
16 ONE = 1,
17 TWO = 2,
19 namespace o3tl {
20 template<> struct typed_flags<Enum1> : is_typed_flags<Enum1, 0x3> {};
23 enum class Enum2 {
24 ZERO = 0,
25 ONE = 1,
26 TWO = 2,
28 namespace o3tl {
29 template<> struct typed_flags<Enum2> : is_typed_flags<Enum2, 0x3> {};
32 int main()
34 auto v1 = ONE & TWO; // expected-error {{expression always evaluates to zero, lhs=1 rhs=2 [loplugin:expressionalwayszero]}}
35 (void)v1;
36 auto v2 = Enum1::ONE & Enum1::TWO; // expected-error {{expression always evaluates to zero, lhs=1 rhs=2 [loplugin:expressionalwayszero]}}
37 (void)v2;
39 auto v3 = Enum2::ONE;
40 auto v4 = v3 & Enum2::ZERO; // expected-error {{expression always evaluates to zero, lhs=unknown rhs=0 [loplugin:expressionalwayszero]}}
41 (void)v4;
43 auto v5 = Enum2::ONE;
44 v5 &= Enum2::ZERO; // expected-error {{expression always evaluates to zero, lhs=unknown rhs=0 [loplugin:expressionalwayszero]}}
46 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */