10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 19 void ExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
20 if (!getLangOpts().CPlusPlus)
25 unless(has(expr(anyOf(isTypeDependent(), isValueDependent())))),
28 hasType(qualType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
29 isSameOrDerivedFrom(hasName(
"::std::exception")))))))))),
33 hasType(substTemplateTypeParmType().bind(
"templ_type")))),
39 eachOf(has(expr(hasType(namedDecl().bind(
"decl")))), anything()))
44 void ExceptionBaseclassCheck::check(
const MatchFinder::MatchResult &Result) {
45 const auto *BadThrow = Result.Nodes.getNodeAs<CXXThrowExpr>(
"bad_throw");
46 assert(BadThrow &&
"Did not match the throw expression");
48 diag(BadThrow->getSubExpr()->getBeginLoc(),
"throwing an exception whose " 49 "type %0 is not derived from " 51 << BadThrow->getSubExpr()->getType() << BadThrow->getSourceRange();
53 if (
const auto *Template =
54 Result.Nodes.getNodeAs<SubstTemplateTypeParmType>(
"templ_type"))
55 diag(BadThrow->getSubExpr()->getBeginLoc(),
56 "type %0 is a template instantiation of %1", DiagnosticIDs::Note)
57 << BadThrow->getSubExpr()->getType()
58 << Template->getReplacedParameter()->getDecl();
60 if (
const auto *TypeDecl = Result.Nodes.getNodeAs<NamedDecl>(
"decl"))
61 diag(TypeDecl->getBeginLoc(),
"type defined here", DiagnosticIDs::Note);
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//