1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "ExplicitOperatorBoolChecker.h"
6 #include "CustomMatchers.h"
8 void ExplicitOperatorBoolChecker::registerMatchers(MatchFinder
*AstMatcher
) {
9 AstMatcher
->addMatcher(
10 cxxMethodDecl(allOf(isFirstParty(), hasName("operator bool")))
15 void ExplicitOperatorBoolChecker::check(
16 const MatchFinder::MatchResult
&Result
) {
17 const CXXConversionDecl
*Method
=
18 Result
.Nodes
.getNodeAs
<CXXConversionDecl
>("node");
19 const CXXRecordDecl
*Clazz
= Method
->getParent();
21 if (!Method
->isExplicit() && !hasCustomAttribute
<moz_implicit
>(Method
) &&
22 !ASTIsInSystemHeader(Method
->getASTContext(), *Method
) &&
23 isInterestingDeclForImplicitConversion(Method
)) {
24 diag(Method
->getBeginLoc(), "bad implicit conversion operator for %0",
27 diag(Method
->getBeginLoc(), "consider adding the explicit keyword to %0",