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"),
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();
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",