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