aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-08-28 15:44:30 +0000
committerHans Wennborg <hans@hanshq.net>2012-08-28 15:44:30 +0000
commit88617a24adafed42e33d196972f97c72d9a5e0a0 (patch)
tree23a4bc1ce2e82c892fe6d5d723942124f0cebdc1 /test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp
parent9438016db2332aca8b53fd953da06128373cc5be (diff)
Warn about suspicious implicit conversions from floating point to bool
This warns in two specific situations: 1) For potentially swapped function arguments, e.g. void foo(bool, float); foo(1.7, false); 2) Misplaced brackets around function call arguments, e.g. bool InRange = fabs(a - b < delta); Where the last argument in a function call is implicitly converted from bool to float, and the function returns a float which gets implicitly converted to bool. Patch by Andreas Eckleder! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162763 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp')
-rw-r--r--test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp b/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp
new file mode 100644
index 0000000000..1d8037aceb
--- /dev/null
+++ b/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+float foof(float x);
+double food(double x);
+void foo(bool b, float f);
+
+void bar() {
+
+ float c = 1.7;
+ bool b = c;
+
+ double e = 1.7;
+ b = e;
+
+ b = foof(4.0);
+
+ b = foof(c < 1); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}}
+
+ b = food(e < 2); // expected-warning {{implicit conversion turns floating-point number into bool: 'double' to 'bool'}}
+
+ foo(c, b); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}}
+ foo(c, c);
+
+}