• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -verify -fsyntax-only %s -Wdouble-promotion
2 
ReturnFloatFromDouble(double d)3 float ReturnFloatFromDouble(double d) {
4   return d;
5 }
6 
ReturnFloatFromLongDouble(long double ld)7 float ReturnFloatFromLongDouble(long double ld) {
8   return ld;
9 }
10 
ReturnDoubleFromLongDouble(long double ld)11 double ReturnDoubleFromLongDouble(long double ld) {
12   return ld;
13 }
14 
ReturnDoubleFromFloat(float f)15 double ReturnDoubleFromFloat(float f) {
16   return f;  //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
17 }
18 
ReturnLongDoubleFromFloat(float f)19 long double ReturnLongDoubleFromFloat(float f) {
20   return f;  //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}}
21 }
22 
ReturnLongDoubleFromDouble(double d)23 long double ReturnLongDoubleFromDouble(double d) {
24   return d;  //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}}
25 }
26 
Assignment(float f,double d,long double ld)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 
ArgumentPassing(float f,double d)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 
BinaryOperator(float f,double d,long double ld)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 
MultiplicationAssignment(float f,double d,long double ld)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.
ConditionalOperator(float f,double d,long double ld,int i)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 }
75