1 // RUN: %clang_cc1 %s -verify -Wno-conversion -Wimplicit-int-float-conversion
2 
3 long testReturn(long a, float b) {
4   return a + b; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
5 }
6 
7 void testAssignment() {
8   float f = 222222;
9   double b = 222222222222L;
10 
11   float ff = 222222222222L;    // expected-warning {{changes value from 222222222222 to 222222221312}}
12   float ffff = 222222222222UL; // expected-warning {{changes value from 222222222222 to 222222221312}}
13 
14   long l = 222222222222L;
15   float fff = l; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
16 }
17 
18 void testExpression() {
19   float a = 0.0f;
20 
21   float b = 222222222222L + a; // expected-warning {{changes value from 222222222222 to 222222221312}}
22 
23   float g = 22222222 + 22222222;
24   float c = 22222222 + 22222223; // expected-warning {{implicit conversion from 'int' to 'float' changes value from 44444445 to 44444444}}
25 
26   int i = 0;
27   float d = i + a; // expected-warning {{implicit conversion from 'int' to 'float' may lose precision}}
28 
29   double e = 0.0;
30   double f = i + e;
31 }
32 
33 void testCNarrowing() {
34   // Since this is a C file. C++11 narrowing is not in effect.
35   // In this case, we should issue warnings.
36   float a = {222222222222L}; // expected-warning {{changes value from 222222222222 to 222222221312}}
37 
38   long b = 222222222222L;
39   float c = {b}; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
40 }
41