NeedsNoVTableTypeChecker.cpp (1381B)
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 "NeedsNoVTableTypeChecker.h" 6 #include "CustomMatchers.h" 7 8 void NeedsNoVTableTypeChecker::registerMatchers(MatchFinder *AstMatcher) { 9 AstMatcher->addMatcher( 10 classTemplateSpecializationDecl( 11 allOf(hasAnyTemplateArgument(refersToType(hasVTable())), 12 hasNeedsNoVTableTypeAttr())) 13 .bind("node"), 14 this); 15 } 16 17 void NeedsNoVTableTypeChecker::check(const MatchFinder::MatchResult &Result) { 18 const ClassTemplateSpecializationDecl *Specialization = 19 Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("node"); 20 21 // Get the offending template argument 22 QualType Offender; 23 const TemplateArgumentList &Args = 24 Specialization->getTemplateInstantiationArgs(); 25 for (unsigned i = 0; i < Args.size(); ++i) { 26 Offender = Args[i].getAsType(); 27 if (typeHasVTable(Offender)) { 28 break; 29 } 30 } 31 32 diag(Specialization->getBeginLoc(), 33 "%0 cannot be instantiated because %1 has a VTable", 34 DiagnosticIDs::Error) 35 << Specialization << Offender; 36 diag(Specialization->getPointOfInstantiation(), 37 "bad instantiation of %0 requested here", DiagnosticIDs::Note) 38 << Specialization; 39 }