| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify -fsyntax-only %s -Wdouble-promotion |
| 2 |
|
| 3 |
float ReturnFloatFromDouble(double d) { |
| 4 |
return d; |
| 5 |
} |
| 6 |
|
| 7 |
float ReturnFloatFromLongDouble(long double ld) { |
| 8 |
return ld; |
| 9 |
} |
| 10 |
|
| 11 |
double ReturnDoubleFromLongDouble(long double ld) { |
| 12 |
return ld; |
| 13 |
} |
| 14 |
|
| 15 |
double ReturnDoubleFromFloat(float f) { |
| 16 |
return f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 17 |
} |
| 18 |
|
| 19 |
long double ReturnLongDoubleFromFloat(float f) { |
| 20 |
return f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 21 |
} |
| 22 |
|
| 23 |
long double ReturnLongDoubleFromDouble(double d) { |
| 24 |
return d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 25 |
} |
| 26 |
|
| 27 |
void Assignment(float f, double d, long double ld) { |
| 28 |
d = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 29 |
ld = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 30 |
ld = d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 31 |
f = d; |
| 32 |
f = ld; |
| 33 |
d = ld; |
| 34 |
} |
| 35 |
|
| 36 |
extern void DoubleParameter(double); |
| 37 |
extern void LongDoubleParameter(long double); |
| 38 |
|
| 39 |
void ArgumentPassing(float f, double d) { |
| 40 |
DoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 41 |
LongDoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 42 |
LongDoubleParameter(d); // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 43 |
} |
| 44 |
|
| 45 |
void BinaryOperator(float f, double d, long double ld) { |
| 46 |
f = f * d; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 47 |
f = d * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 48 |
f = f * ld; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 49 |
f = ld * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 50 |
d = d * ld; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 51 |
d = ld * d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 52 |
} |
| 53 |
|
| 54 |
void MultiplicationAssignment(float f, double d, long double ld) { |
| 55 |
d *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 56 |
ld *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 57 |
ld *= d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 58 |
|
| 59 |
// FIXME: These cases should produce warnings as above. |
| 60 |
f *= d; |
| 61 |
f *= ld; |
| 62 |
d *= ld; |
| 63 |
} |
| 64 |
|
| 65 |
// FIXME: As with a binary operator, the operands to the conditional operator are |
| 66 |
// converted to a common type and should produce a warning. |
| 67 |
void ConditionalOperator(float f, double d, long double ld, int i) { |
| 68 |
f = i ? f : d; |
| 69 |
f = i ? d : f; |
| 70 |
f = i ? f : ld; |
| 71 |
f = i ? ld : f; |
| 72 |
d = i ? d : ld; |
| 73 |
d = i ? ld : d; |
| 74 |
} |