2020-04-24 09:45:48 +08:00
|
|
|
// RUN: %clang_cc1 %s -verify -Wno-constant-conversion
|
|
|
|
// RUN: %clang_cc1 %s -verify -Wno-constant-conversion -Wno-implicit-int-float-conversion -Wimplicit-const-int-float-conversion
|
|
|
|
// RUN: %clang_cc1 %s -DNONCONST=1 -verify -Wno-constant-conversion -Wimplicit-int-float-conversion
|
2019-08-01 08:16:43 +08:00
|
|
|
|
2020-04-23 00:53:35 +08:00
|
|
|
#ifdef NONCONST
|
2019-08-01 08:16:43 +08:00
|
|
|
long testReturn(long a, float b) {
|
|
|
|
return a + b; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
|
|
|
|
}
|
2020-04-23 00:53:35 +08:00
|
|
|
#endif
|
2019-08-01 08:16:43 +08:00
|
|
|
|
|
|
|
void testAssignment() {
|
|
|
|
float f = 222222;
|
|
|
|
double b = 222222222222L;
|
|
|
|
|
2019-08-01 09:39:21 +08:00
|
|
|
float ff = 222222222222L; // expected-warning {{changes value from 222222222222 to 222222221312}}
|
|
|
|
float ffff = 222222222222UL; // expected-warning {{changes value from 222222222222 to 222222221312}}
|
2019-08-01 08:16:43 +08:00
|
|
|
|
|
|
|
long l = 222222222222L;
|
2020-09-23 07:51:23 +08:00
|
|
|
#ifdef NONCONST
|
2019-08-01 08:16:43 +08:00
|
|
|
float fff = l; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
|
2020-04-23 00:53:35 +08:00
|
|
|
#endif
|
2019-08-01 08:16:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void testExpression() {
|
|
|
|
float a = 0.0f;
|
|
|
|
|
2019-08-01 09:39:21 +08:00
|
|
|
float b = 222222222222L + a; // expected-warning {{changes value from 222222222222 to 222222221312}}
|
2019-08-01 08:16:43 +08:00
|
|
|
|
|
|
|
float g = 22222222 + 22222222;
|
|
|
|
float c = 22222222 + 22222223; // expected-warning {{implicit conversion from 'int' to 'float' changes value from 44444445 to 44444444}}
|
|
|
|
|
|
|
|
int i = 0;
|
2020-04-23 00:53:35 +08:00
|
|
|
#ifdef NONCONST
|
2019-08-01 08:16:43 +08:00
|
|
|
float d = i + a; // expected-warning {{implicit conversion from 'int' to 'float' may lose precision}}
|
2020-04-23 00:53:35 +08:00
|
|
|
#endif
|
2019-08-01 08:16:43 +08:00
|
|
|
|
|
|
|
double e = 0.0;
|
|
|
|
double f = i + e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testCNarrowing() {
|
|
|
|
// Since this is a C file. C++11 narrowing is not in effect.
|
|
|
|
// In this case, we should issue warnings.
|
2019-08-01 09:39:21 +08:00
|
|
|
float a = {222222222222L}; // expected-warning {{changes value from 222222222222 to 222222221312}}
|
2019-08-01 08:16:43 +08:00
|
|
|
|
|
|
|
long b = 222222222222L;
|
2020-04-23 00:53:35 +08:00
|
|
|
#ifdef NONCONST
|
2019-08-01 08:16:43 +08:00
|
|
|
float c = {b}; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
|
2020-04-23 00:53:35 +08:00
|
|
|
#endif
|
2019-08-01 08:16:43 +08:00
|
|
|
}
|