Files
sousa-gecko/build/clang-plugin/ExplicitOperatorBoolChecker.cpp
T
serge-sans-paille 60e367c3c4 Bug 2019521 - Move clang-tidy logic from checker to matcher r=sylvestre,firefox-static-analysis-reviewers
This should save memory and compilation time by not creating an unused
context. It also clearly conveys the pattern caught by the pass.

Concerning compilation speed, let's take the example of
`Unified_cpp_js_src_jit5.cpp`.

Without clang-plugin, it takes:         10.603 s ±  0.183 s to compile.
With clang-plugin, before this patch:   14.188 s ±  0.230 s to compile
With clang-plugin, after this patch:    14.108 s ±  0.772 s to compile

So that's roughly 3.59s spent into the plugin, down to 3.51 with this
patch, a marginal 2% speedup on the plugin efficiency.

Differential Revision: https://phabricator.services.mozilla.com/D285008
2026-03-05 09:08:52 +00:00

30 lines
1.1 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ExplicitOperatorBoolChecker.h"
#include "CustomMatchers.h"
void ExplicitOperatorBoolChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
cxxConversionDecl(isFirstParty(), hasName("operator bool"),
isInterestingForImplicitConversion(),
unless(anyOf(isExplicit(), isMarkedImplicit())))
.bind("node"),
this);
}
void ExplicitOperatorBoolChecker::check(
const MatchFinder::MatchResult &Result) {
const CXXConversionDecl *Method =
Result.Nodes.getNodeAs<CXXConversionDecl>("node");
const CXXRecordDecl *Clazz = Method->getParent();
diag(Method->getBeginLoc(), "bad implicit conversion operator for %0",
DiagnosticIDs::Error)
<< Clazz;
diag(Method->getBeginLoc(), "consider adding the explicit keyword to %0",
DiagnosticIDs::Note)
<< "'operator bool'";
}