bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / test / intvsfloat.cxx
blob4746873e7bbadb27a716473ef5c5892bfc6f0ab7
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 static const float PI = 3.4;
11 struct Class1
13 float getFloat() const { return 1.5; }
14 int getInt() const { return 1; }
15 static constexpr float PI = 3.4;
16 static constexpr float E() { return 3.4; }
19 void func1(Class1 const& class1)
21 // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
22 if (1 == PI)
23 return;
24 // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
25 if (1 == class1.PI)
26 return;
27 // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
28 if (true == class1.PI)
29 return;
30 if (1 == class1.getInt()) // no warning expected
31 return;
32 // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
33 if (1 == class1.E())
34 return;
35 // expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}}
36 if (true == class1.E())
37 return;
38 if (1 == class1.getFloat()) // no warning expected
39 return;
42 void func2(Class1 const& class1)
44 // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
45 int i0 = PI;
46 (void)i0;
47 // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
48 int i1 = class1.PI;
49 (void)i1;
50 // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
51 int i2 = class1.E();
52 (void)i2;
53 int i3 = class1.getFloat(); // no warning expected
54 (void)i3;
55 int i4 = class1.getInt(); // no warning expected
56 (void)i4;
57 // expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}}
58 bool b1 = class1.E();
59 (void)b1;
62 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */