| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify -fsyntax-only %s -Wdouble-promotion |
| 2 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify -fsyntax-only -x c++ %s -Wdouble-promotion |
| 3 |
|
| 4 |
float ReturnFloatFromDouble(double d) { |
| 5 |
return d; |
| 6 |
} |
| 7 |
|
| 8 |
float ReturnFloatFromLongDouble(long double ld) { |
| 9 |
return ld; |
| 10 |
} |
| 11 |
|
| 12 |
double ReturnDoubleFromLongDouble(long double ld) { |
| 13 |
return ld; |
| 14 |
} |
| 15 |
|
| 16 |
double ReturnDoubleFromFloat(float f) { |
| 17 |
return f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 18 |
} |
| 19 |
|
| 20 |
long double ReturnLongDoubleFromFloat(float f) { |
| 21 |
return f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 22 |
} |
| 23 |
|
| 24 |
long double ReturnLongDoubleFromDouble(double d) { |
| 25 |
return d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 26 |
} |
| 27 |
|
| 28 |
double ReturnDoubleFromFloatWithExplicitCast(float f) { |
| 29 |
return (double)f; |
| 30 |
} |
| 31 |
|
| 32 |
long double ReturnLongDoubleFromFloatWithExplicitCast(float f) { |
| 33 |
return (long double)f; |
| 34 |
} |
| 35 |
|
| 36 |
long double ReturnLongDoubleFromDoubleWithExplicitCast(double d) { |
| 37 |
return (long double)d; |
| 38 |
} |
| 39 |
|
| 40 |
void Assignment(float f, double d, long double ld) { |
| 41 |
d = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 42 |
ld = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 43 |
ld = d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 44 |
d = (double)f; |
| 45 |
ld = (long double)f; |
| 46 |
ld = (long double)d; |
| 47 |
f = d; |
| 48 |
f = ld; |
| 49 |
d = ld; |
| 50 |
} |
| 51 |
|
| 52 |
void AssignmentWithExtraParens(float f, double d, long double ld) { |
| 53 |
d = (f); //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 54 |
ld = (f); //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 55 |
ld = (d); //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 56 |
d = (double)(f); |
| 57 |
ld = (long double)(f); |
| 58 |
ld = (long double)(d); |
| 59 |
} |
| 60 |
|
| 61 |
extern void DoubleParameter(double); |
| 62 |
extern void LongDoubleParameter(long double); |
| 63 |
|
| 64 |
void ArgumentPassing(float f, double d) { |
| 65 |
DoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 66 |
LongDoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 67 |
LongDoubleParameter(d); // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 68 |
DoubleParameter((double)f); |
| 69 |
LongDoubleParameter((long double)f); |
| 70 |
LongDoubleParameter((long double)d); |
| 71 |
} |
| 72 |
|
| 73 |
void BinaryOperator(float f, double d, long double ld) { |
| 74 |
f = f * d; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 75 |
f = d * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 76 |
f = f * ld; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 77 |
f = ld * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 78 |
d = d * ld; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 79 |
d = ld * d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 80 |
f = (double)f * d; |
| 81 |
f = d * (double)f; |
| 82 |
f = (long double)f * ld; |
| 83 |
f = ld * (long double)f; |
| 84 |
d = (long double)d * ld; |
| 85 |
d = ld * (long double)d; |
| 86 |
} |
| 87 |
|
| 88 |
void MultiplicationAssignment(float f, double d, long double ld) { |
| 89 |
d *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 90 |
ld *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 91 |
ld *= d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 92 |
d *= (double)f; |
| 93 |
ld *= (long double)f; |
| 94 |
ld *= (long double)d; |
| 95 |
|
| 96 |
// FIXME: These cases should produce warnings as above. |
| 97 |
f *= d; |
| 98 |
f *= ld; |
| 99 |
d *= ld; |
| 100 |
} |
| 101 |
|
| 102 |
// FIXME: As with a binary operator, the operands to the conditional operator are |
| 103 |
// converted to a common type and should produce a warning. |
| 104 |
void ConditionalOperator(float f, double d, long double ld, int i) { |
| 105 |
f = i ? f : d; |
| 106 |
f = i ? d : f; |
| 107 |
f = i ? f : ld; |
| 108 |
f = i ? ld : f; |
| 109 |
d = i ? d : ld; |
| 110 |
d = i ? ld : d; |
| 111 |
} |