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 "ExplicitImplicitChecker.h"
6 #include "CustomMatchers.h"
8 void ExplicitImplicitChecker::registerMatchers(MatchFinder
*AstMatcher
) {
9 AstMatcher
->addMatcher(
11 isInterestingImplicitCtor(),
12 ofClass(allOf(isConcreteClass(), decl().bind("class"))),
13 unless(isMarkedImplicit()))
18 void ExplicitImplicitChecker::check(const MatchFinder::MatchResult
&Result
) {
19 // We've already checked everything in the matcher, so we just have to report
22 const CXXConstructorDecl
*Ctor
=
23 Result
.Nodes
.getNodeAs
<CXXConstructorDecl
>("ctor");
24 const CXXRecordDecl
*Declaration
=
25 Result
.Nodes
.getNodeAs
<CXXRecordDecl
>("class");
28 FixItHint::CreateInsertion(Ctor
->getLocation(), "explicit ");
29 diag(Ctor
->getLocation(), "bad implicit conversion constructor for %0",
31 << Declaration
->getDeclName();
32 diag(Ctor
->getLocation(),
33 "consider adding the explicit keyword to the constructor",