Bug 1686610 [wpt PR 27178] - Update <link> pseudo selector WPTs, a=testonly
[gecko.git] / build / clang-plugin / ParamTraitsEnumChecker.cpp
blob7214e9fe5be3105247f6acc1c5fd1575f0e9b58e
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 "ParamTraitsEnumChecker.h"
6 #include "CustomMatchers.h"
8 void ParamTraitsEnumChecker::registerMatchers(MatchFinder *AstMatcher) {
9 AstMatcher->addMatcher(
10 classTemplateSpecializationDecl(hasName("ParamTraits")).bind("decl"),
11 this);
14 void ParamTraitsEnumChecker::check(const MatchFinder::MatchResult &Result) {
15 const ClassTemplateSpecializationDecl *Decl =
16 Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("decl");
18 for (auto &Inner : Decl->decls()) {
19 if (auto *Def = dyn_cast<TypedefDecl>(Inner)) {
20 QualType UnderlyingType = Def->getUnderlyingType();
21 QualType CanonicalType = UnderlyingType.getCanonicalType();
23 const clang::Type *TypePtr = CanonicalType.getTypePtrOrNull();
24 if (!TypePtr) {
25 return;
28 if (TypePtr->isEnumeralType()) {
29 diag(Decl->getBeginLoc(),
30 "Custom ParamTraits implementation for an enum type",
31 DiagnosticIDs::Error);
32 diag(Decl->getBeginLoc(),
33 "Please use a helper class for example ContiguousEnumSerializer",
34 DiagnosticIDs::Note);