Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / build / clang-plugin / ExplicitImplicitChecker.cpp
blobe0620f502f4a48362112d0400468f76f0268b452
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(
10 cxxConstructorDecl(
11 isInterestingImplicitCtor(),
12 ofClass(allOf(isConcreteClass(), decl().bind("class"))),
13 unless(isMarkedImplicit()))
14 .bind("ctor"),
15 this);
18 void ExplicitImplicitChecker::check(const MatchFinder::MatchResult &Result) {
19 // We've already checked everything in the matcher, so we just have to report
20 // the error.
22 const CXXConstructorDecl *Ctor =
23 Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
24 const CXXRecordDecl *Declaration =
25 Result.Nodes.getNodeAs<CXXRecordDecl>("class");
27 FixItHint FixItHint =
28 FixItHint::CreateInsertion(Ctor->getLocation(), "explicit ");
29 diag(Ctor->getLocation(), "bad implicit conversion constructor for %0",
30 DiagnosticIDs::Error)
31 << Declaration->getDeclName();
32 diag(Ctor->getLocation(),
33 "consider adding the explicit keyword to the constructor",
34 DiagnosticIDs::Note)
35 << FixItHint;