|
| 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 | +double ReturnDoubleFromFloatWithExplicitCast(float f) { |
| 28 | + return static_cast<double>(f); |
| 29 | +} |
| 30 | + |
| 31 | +long double ReturnLongDoubleFromFloatWithExplicitCast(float f) { |
| 32 | + return static_cast<long double>(f); |
| 33 | +} |
| 34 | + |
| 35 | +long double ReturnLongDoubleFromDoubleWithExplicitCast(double d) { |
| 36 | + return static_cast<long double>(d); |
| 37 | +} |
| 38 | + |
| 39 | +double ReturnDoubleFromFloatWithExplicitListInitialization(float f) { |
| 40 | + return double{f}; |
| 41 | +} |
| 42 | + |
| 43 | +long double ReturnLongDoubleFromFloatWithExplicitListInitialization(float f) { |
| 44 | + return (long double){f}; |
| 45 | +} |
| 46 | + |
| 47 | +long double ReturnLongDoubleFromDoubleWithExplicitListInitialization(double d) { |
| 48 | + return (long double){d}; |
| 49 | +} |
| 50 | + |
| 51 | +void Assignment(float f, double d, long double ld) { |
| 52 | + d = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 53 | + ld = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 54 | + ld = d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 55 | + d = static_cast<double>(f); |
| 56 | + ld = static_cast<long double>(f); |
| 57 | + ld = static_cast<long double>(d); |
| 58 | + d = double{f}; |
| 59 | + ld = (long double){f}; |
| 60 | + ld = (long double){d}; |
| 61 | + f = d; |
| 62 | + f = ld; |
| 63 | + d = ld; |
| 64 | +} |
| 65 | + |
| 66 | +extern void DoubleParameter(double); |
| 67 | +extern void LongDoubleParameter(long double); |
| 68 | + |
| 69 | +void ArgumentPassing(float f, double d) { |
| 70 | + DoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 71 | + LongDoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 72 | + LongDoubleParameter(d); // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 73 | + DoubleParameter(static_cast<double>(f)); |
| 74 | + LongDoubleParameter(static_cast<long double>(f)); |
| 75 | + LongDoubleParameter(static_cast<long double>(d)); |
| 76 | + DoubleParameter(double{f}); |
| 77 | + LongDoubleParameter((long double){f}); |
| 78 | + LongDoubleParameter((long double){d}); |
| 79 | +} |
| 80 | + |
| 81 | +void BinaryOperator(float f, double d, long double ld) { |
| 82 | + f = f * d; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 83 | + f = d * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 84 | + f = f * ld; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 85 | + f = ld * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 86 | + d = d * ld; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 87 | + d = ld * d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 88 | + f = static_cast<double>(f) * d; |
| 89 | + f = d * static_cast<double>(f); |
| 90 | + f = static_cast<long double>(f) * ld; |
| 91 | + f = ld * static_cast<long double>(f); |
| 92 | + d = static_cast<long double>(d) * ld; |
| 93 | + d = ld * static_cast<long double>(d); |
| 94 | + f = double{f} * d; |
| 95 | + f = d * double{f}; |
| 96 | + f = (long double){f} * ld; |
| 97 | + f = ld * (long double){f}; |
| 98 | + d = (long double){d} * ld; |
| 99 | + d = ld * (long double){d}; |
| 100 | +} |
| 101 | + |
| 102 | +void MultiplicationAssignment(float f, double d, long double ld) { |
| 103 | + d *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} |
| 104 | + ld *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} |
| 105 | + ld *= d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} |
| 106 | + d *= static_cast<double>(f); |
| 107 | + ld *= static_cast<long double>(f); |
| 108 | + ld *= static_cast<long double>(d); |
| 109 | + d *= double{f}; |
| 110 | + ld *= (long double){f}; |
| 111 | + ld *= (long double){d}; |
| 112 | + |
| 113 | + // FIXME: These cases should produce warnings as above. |
| 114 | + f *= d; |
| 115 | + f *= ld; |
| 116 | + d *= ld; |
| 117 | +} |
| 118 | + |
| 119 | +// FIXME: As with a binary operator, the operands to the conditional operator are |
| 120 | +// converted to a common type and should produce a warning. |
| 121 | +void ConditionalOperator(float f, double d, long double ld, int i) { |
| 122 | + f = i ? f : d; |
| 123 | + f = i ? d : f; |
| 124 | + f = i ? f : ld; |
| 125 | + f = i ? ld : f; |
| 126 | + d = i ? d : ld; |
| 127 | + d = i ? ld : d; |
| 128 | +} |
0 commit comments