Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / build / clang-plugin / ExplicitOperatorBoolChecker.cpp
blobed97335a00c1242f9997e276af47acef9aa7bcd1
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")))
11 .bind("node"),
12 this);
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",
25 DiagnosticIDs::Error)
26 << Clazz;
27 diag(Method->getBeginLoc(), "consider adding the explicit keyword to %0",
28 DiagnosticIDs::Note)
29 << "'operator bool'";