Fix typo
[LibreOffice.git] / compilerplugins / clang / test / implicitboolconversion.cxx
blob122ee363ae681140877e16a26d61067489c41126
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 <sal/config.h>
12 #include <array>
13 #include <atomic>
14 #include <initializer_list>
16 #include <com/sun/star/uno/Sequence.hxx>
17 #include <sal/types.h>
19 template <typename T> struct Sequence
21 Sequence(std::initializer_list<T>);
24 template <typename T> struct Wrap1
26 T element;
29 template <typename T> struct Wrap2
31 Wrap2(T const& e)
32 : element(e)
35 T element;
38 bool g();
40 void h(bool);
42 void f()
44 // expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
45 int i = false;
46 // expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
47 i = true;
48 (void)i;
49 std::atomic<bool> b = false;
50 (void)b;
51 //TODO: Emit only one diagnostic here:
52 // expected-error@+2 {{implicit conversion (ConstructorConversion) from 'bool' to 'std::atomic<int>' [loplugin:implicitboolconversion]}}
53 // expected-error-re@+1 {{implicit conversion (IntegralCast) from 'bool' to {{.+}} [loplugin:implicitboolconversion]}}
54 std::atomic<int> a = false;
55 (void)a;
56 bool b2 = true;
57 b2 &= g();
58 (void)b2;
59 Sequence<sal_Bool> s1{ false };
60 (void)s1;
61 Sequence<Sequence<sal_Bool>> s2{ { false } };
62 (void)s2;
63 // expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'const int' [loplugin:implicitboolconversion]}}
64 Sequence<int> s3{ false };
65 (void)s3;
66 // expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'const int' [loplugin:implicitboolconversion]}}
67 Sequence<Sequence<int>> s4{ { false } };
68 (void)s4;
69 Wrap1<sal_Bool> w1{ false };
70 Sequence<Wrap1<sal_Bool>> s5{ { false } };
71 (void)s5;
72 Wrap2<sal_Bool> w2{ false };
73 (void)w2;
74 Sequence<Wrap2<sal_Bool>> s6{ { false } };
75 (void)s6;
76 h(w1.element);
77 css::uno::Sequence<sal_Bool> s7(1);
78 h(s7[0]);
79 std::array<sal_Bool, 1> s8;
80 s8[0] = false;
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */