1 // RUN: %clang_cc1 -fsyntax-only -Wfloat-equal -verify %s
3 int f1(float x
, float y
) {
4 return x
== y
; // expected-warning {{comparing floating point with ==}}
7 int f2(float x
, float y
) {
8 return x
!= y
; // expected-warning {{comparing floating point with ==}}
12 return x
== x
; // no-warning
15 // 0.0 can be represented exactly, so don't warn.
17 return x
== 0.0; // no-warning {{comparing}}
21 return x
== __builtin_inf(); // no-warning
24 // The literal is a double that can't be represented losslessly as a float.
25 int tautological_FP_compare(float x
) {
26 return x
== 3.14159; // expected-warning {{floating-point comparison is always false}}
29 int tautological_FP_compare_inverse(float x
) {
30 return x
!= 3.14159; // expected-warning {{floating-point comparison is always true}}
33 // The literal is a double that can be represented losslessly as a long double,
34 // but this might not be the comparison what was intended.
35 int not_tautological_FP_compare(long double f
) {
36 return f
== 0.1; // expected-warning {{comparing floating point with ==}}
39 int tautological_FP_compare_commute(float f
) {
40 return 0.3 == f
; // expected-warning {{floating-point comparison is always false}}
43 int tautological_FP_compare_commute_inverse(float f
) {
44 return 0.3 != f
; // expected-warning {{floating-point comparison is always true}}
47 int tautological_FP_compare_explicit_upcast(float f
) {
48 return 0.3 == (double) f
; // expected-warning {{floating-point comparison is always false}}
51 int tautological_FP_compare_explicit_downcast(double d
) {
52 return 0.3 == (float) d
; // expected-warning {{floating-point comparison is always false}}
55 int tautological_FP_compare_ignore_parens(float f
) {
56 return f
== (0.3); // expected-warning {{floating-point comparison is always false}}
61 int tautological_FP_compare_macro(float f
) {
62 return f
== CST
; // expected-warning {{floating-point comparison is always false}}