[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Sema / floating-point-compare.c
blob4ccfae203f9d10e92df3bf569fc8cf6374164986
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 ==}}
5 }
7 int f2(float x, float y) {
8 return x != y; // expected-warning {{comparing floating point with ==}}
11 int f3(float x) {
12 return x == x; // no-warning
15 // 0.0 can be represented exactly, so don't warn.
16 int f4(float x) {
17 return x == 0.0; // no-warning {{comparing}}
20 int f5(float x) {
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}}
59 #define CST 0.3
61 int tautological_FP_compare_macro(float f) {
62 return f == CST; // expected-warning {{floating-point comparison is always false}}