summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2015-10-25 15:31:25 +0000
committerPiotr Dziwinski <piotrdz@gmail.com>2015-10-25 15:31:25 +0000
commit7f1b5099d7d93da4947ec7114e95671992941f94 (patch)
treeec1ee1b887ba6258a9d5ba1fe088e5b2090667f9 /clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp
parentbf45e742540cd14e44a2a065d8b9a32b49e95957 (diff)
downloadbcm5719-llvm-7f1b5099d7d93da4947ec7114e95671992941f94.tar.gz
bcm5719-llvm-7f1b5099d7d93da4947ec7114e95671992941f94.zip
[clang-tidy] Add check readability-implicit-bool-cast
Summary: This is another check that I ported to clang-tidy from colobot-lint tool. As previously discussed on cfe-dev mailing list, this is one of those checks that I think is general and useful enough for contribution to clang-tidy. This patch contains implementation of check taken from colobot-lint, but it is extended a great deal, including FixIt hints for automated refactoring, exhaustive testcases, and user documentation. Reviewers: sbenza, aaron.ballman, alexfh Subscribers: Eugene.Zelenko Differential Revision: http://reviews.llvm.org/D13635 llvm-svn: 251235
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp b/clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp
new file mode 100644
index 00000000000..1cd5c87d335
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/readability-implicit-bool-cast-cxx98.cpp
@@ -0,0 +1,42 @@
+// RUN: clang-tidy %s -checks=-*,readability-implicit-bool-cast -- -std=c++98
+
+#include <cstddef> // for NULL
+
+template<typename T>
+void functionTaking(T);
+
+struct Struct {
+ int member;
+};
+
+void useOldNullMacroInReplacements() {
+ int* pointer = NULL;
+ functionTaking<bool>(pointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit cast 'int *' -> bool [readability-implicit-bool-cast]
+ // CHECK-FIXES: functionTaking<bool>(pointer != 0);
+
+ int Struct::* memberPointer = NULL;
+ functionTaking<bool>(!memberPointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit cast 'int struct Struct::*' -> bool
+ // CHECK-FIXES: functionTaking<bool>(memberPointer == 0);
+}
+
+void fixFalseLiteralConvertingToNullPointer() {
+ functionTaking<int*>(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit cast bool -> 'int *'
+ // CHECK-FIXES: functionTaking<int*>(0);
+
+ int* pointer = NULL;
+ if (pointer == false) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicit cast bool -> 'int *'
+ // CHECK-FIXES: if (pointer == 0) {}
+
+ functionTaking<int Struct::*>(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit cast bool -> 'int struct Struct::*'
+ // CHECK-FIXES: functionTaking<int Struct::*>(0);
+
+ int Struct::* memberPointer = NULL;
+ if (memberPointer != false) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit cast bool -> 'int struct Struct::*'
+ // CHECK-FIXES: if (memberPointer != 0) {}
+}
OpenPOWER on IntegriCloud