[PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.
Etienne Bergeron via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 2 04:32:45 PDT 2016
etienneb added a comment.
In http://reviews.llvm.org/D20857#446654, @murrayc wrote:
> In http://reviews.llvm.org/D20857#446101, @etienneb wrote:
>
> > I wonder if these two checks should not be merge in one checker.
>
>
> Personally I find it cleaner to keep them separate, but I would be happy to combine them if that's wanted. I guessed that it would be easier to accept the explicit bool check than the operator void pointer check, and didn't want to make acceptance harder. I can also imagine someone wanting to disable one but not the other.
Enabling/disabling can be done with options (see SizeofExpressionCheck).
WarnOnSizeOfConstant(Options.get("WarnOnSizeOfConstant", 1) != 0),
WarnOnSizeOfThis(Options.get("WarnOnSizeOfThis", 1) != 0),
WarnOnSizeOfCompareToConstant(
Options.get("WarnOnSizeOfCompareToConstant", 1) != 0) {}
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:20
@@ +19,3 @@
+
+AST_MATCHER(QualType, isVoid) {
+return Node->isVoidType();
----------------
this matcher exists? ***voidType***
```
Matches type void.
Given
struct S { void func(); };
functionDecl(returns(voidType()))
matches "void func();"
```
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:21
@@ +20,3 @@
+AST_MATCHER(QualType, isVoid) {
+return Node->isVoidType();
+}
----------------
nit: indent + 2
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:31
@@ +30,3 @@
+ cxxConversionDecl(
+ returns(pointerType(pointee(isConstQualified(), isVoid()))), unless(isExplicit())).bind("operator-void-pointer"), this);
+}
----------------
indentation is wrong.
Run clang-format over it
% clang-format -style=file <your-file> -i
================
Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:35
@@ +34,3 @@
+void OperatorVoidPointerCheck::check(const MatchFinder::MatchResult &Result) {
+ const auto* MatchedDecl =
+ Result.Nodes.getNodeAs<CXXConversionDecl>("operator-void-pointer");
----------------
pointer lean to right:
```
const auto* MatchedDecl
-->
const auto *MatchedDecl
```
http://reviews.llvm.org/D20857
More information about the cfe-commits
mailing list