diff options
author | Sergio Martins <smartins@kde.org> | 2017-06-20 23:33:50 +0100 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2017-06-20 23:33:50 +0100 |
commit | 475e925cbd4eddda6fd33e2b7c26bd5576890a27 (patch) | |
tree | 708089beae5664b3a00747e2985a5f50271eda5f /tests/implicit-casts | |
parent | a123519dfe9b579b1d8f88aff71f3abd7a4baa77 (diff) |
implicit-casts: warn on bool to int implicit casts
Disabled by default due to false positives when calling C functions
or even C++ sometimes.
You can enable it with:
export CLAZY_EXTRA_OPTIONS=implicit-casts-bool-to-int
Diffstat (limited to 'tests/implicit-casts')
-rw-r--r-- | tests/implicit-casts/bool2int.cpp | 31 | ||||
-rw-r--r-- | tests/implicit-casts/bool2int.cpp.expected | 5 | ||||
-rw-r--r-- | tests/implicit-casts/config.json | 4 |
3 files changed, 40 insertions, 0 deletions
diff --git a/tests/implicit-casts/bool2int.cpp b/tests/implicit-casts/bool2int.cpp new file mode 100644 index 00000000..89ca5fa5 --- /dev/null +++ b/tests/implicit-casts/bool2int.cpp @@ -0,0 +1,31 @@ +#include <QtCore/QDebug> + +struct S { + void operator=(int); +}; + +void foo(int) {} + +extern "C" void takesInt_C(int); +extern void takesInt_Cpp(int); + +struct A +{ + void foo(int); +}; + +void testIntToBool(bool b1) +{ + bool b2; + foo(false); // Warn + foo(b1); // Warn + foo(b2); // Warn + A a; + a.foo(false); // Warn + + takesInt_C(false); // OK + takesInt_Cpp(false); // Warn + + S s; s = false; // OK + qDebug("Foo %d", false); // OK +} diff --git a/tests/implicit-casts/bool2int.cpp.expected b/tests/implicit-casts/bool2int.cpp.expected new file mode 100644 index 00000000..07fd8755 --- /dev/null +++ b/tests/implicit-casts/bool2int.cpp.expected @@ -0,0 +1,5 @@ +implicit-casts/bool2int.cpp:20:9: warning: Implicit bool to int cast (argument 1) [-Wclazy-implicit-casts] +implicit-casts/bool2int.cpp:21:9: warning: Implicit bool to int cast (argument 1) [-Wclazy-implicit-casts] +implicit-casts/bool2int.cpp:22:9: warning: Implicit bool to int cast (argument 1) [-Wclazy-implicit-casts] +implicit-casts/bool2int.cpp:24:11: warning: Implicit bool to int cast (argument 1) [-Wclazy-implicit-casts] +implicit-casts/bool2int.cpp:27:18: warning: Implicit bool to int cast (argument 1) [-Wclazy-implicit-casts] diff --git a/tests/implicit-casts/config.json b/tests/implicit-casts/config.json index e7e6e0cb..9322a3e6 100644 --- a/tests/implicit-casts/config.json +++ b/tests/implicit-casts/config.json @@ -2,6 +2,10 @@ "tests" : [ { "filename" : "main.cpp" + }, + { + "filename" : "bool2int.cpp", + "env" : { "CLAZY_EXTRA_OPTIONS" : "implicit-casts-bool-to-int" } } ] } |