ParamTraitsEnumChecker.cpp (1334B)
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/. */ 4 5 #include "ParamTraitsEnumChecker.h" 6 #include "CustomMatchers.h" 7 8 void ParamTraitsEnumChecker::registerMatchers(MatchFinder *AstMatcher) { 9 AstMatcher->addMatcher( 10 classTemplateSpecializationDecl(hasName("ParamTraits")).bind("decl"), 11 this); 12 } 13 14 void ParamTraitsEnumChecker::check(const MatchFinder::MatchResult &Result) { 15 const ClassTemplateSpecializationDecl *Decl = 16 Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("decl"); 17 18 for (auto &Inner : Decl->decls()) { 19 if (auto *Def = dyn_cast<TypedefDecl>(Inner)) { 20 QualType UnderlyingType = Def->getUnderlyingType(); 21 QualType CanonicalType = UnderlyingType.getCanonicalType(); 22 23 const clang::Type *TypePtr = CanonicalType.getTypePtrOrNull(); 24 if (!TypePtr) { 25 return; 26 } 27 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); 35 } 36 } 37 } 38 }