[PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.
Etienne Bergeron via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 13:11:27 PDT 2016
etienneb added a comment.
I wonder if these two checks should not be merge in one checker.
modernize-explicit-conversion-operator
================
Comment at: clang-tidy/modernize/ExplicitOperatorBoolCheck.cpp:21
@@ +20,3 @@
+void ExplicitOperatorBoolCheck::registerMatchers(MatchFinder *Finder) {
+ Finder->addMatcher(
+ // FIXME: Use some kind of isConversionToType("bool") here,
----------------
As you state later "available since C++11",
you should check for the current language.
Example from other checkers:
```
if (!getLangOpts().CPlusPlus)
return;
```
================
Comment at: clang-tidy/modernize/ExplicitOperatorBoolCheck.cpp:36
@@ +35,3 @@
+ // Or can we at least use a constant here?
+ if (CanonicalType.getAsString() != "_Bool") {
+ return;
----------------
This check should be part of the matcher above.
see: booleanType
```
Matches type bool.
Given
struct S { bool func(); };
functionDecl(returns(booleanType()))
matches "bool func();"
```
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:30
@@ +29,3 @@
+void OperatorVoidPointerCheck::check(const MatchFinder::MatchResult &Result) {
+ const auto MatchedDecl =
+ Result.Nodes.getNodeAs<CXXConversionDecl>("operator-void-pointer");
----------------
nit: const auto *MatchedDecl
and below...
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:37
@@ +36,3 @@
+ // Or can we at least use a constant here?
+ if (CanonicalType.getAsString() != "const void *") {
+ return;
----------------
nit: no { }
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:37
@@ +36,3 @@
+ // Or can we at least use a constant here?
+ if (CanonicalType.getAsString() != "const void *") {
+ return;
----------------
etienneb wrote:
> nit: no { }
should be part of the matcher.
================
Comment at: docs/clang-tidy/checks/list.rst:7
@@ -6,3 +6,2 @@
.. toctree::
-
boost-use-to-string
----------------
why removing this line?
================
Comment at: docs/clang-tidy/checks/modernize-explicit-operator-bool.rst:11
@@ +10,3 @@
+be compared accidentally. For instance, even when objects a and b have no
+operator = overloads, an implicit operator bool would allow `a == b` to compile
+because both a and b can be implictly converted to bool.
----------------
operator = --> operator == ???
Repository:
rL LLVM
http://reviews.llvm.org/D20857
More information about the cfe-commits
mailing list