10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
20 unless(has(expr(anyOf(isTypeDependent(), isValueDependent())))),
23 hasType(qualType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
24 isSameOrDerivedFrom(hasName(
"::std::exception")))))))))),
28 hasType(substTemplateTypeParmType().bind(
"templ_type")))),
34 eachOf(has(expr(hasType(namedDecl().bind(
"decl")))), anything()))
40 const auto *BadThrow = Result.Nodes.getNodeAs<CXXThrowExpr>(
"bad_throw");
41 assert(BadThrow &&
"Did not match the throw expression");
43 diag(BadThrow->getSubExpr()->getBeginLoc(),
"throwing an exception whose "
44 "type %0 is not derived from "
46 << BadThrow->getSubExpr()->getType() << BadThrow->getSourceRange();
48 if (
const auto *Template =
49 Result.Nodes.getNodeAs<SubstTemplateTypeParmType>(
"templ_type"))
50 diag(BadThrow->getSubExpr()->getBeginLoc(),
51 "type %0 is a template instantiation of %1", DiagnosticIDs::Note)
52 << BadThrow->getSubExpr()->getType()
53 << Template->getReplacedParameter();
55 if (
const auto *TypeDecl = Result.Nodes.getNodeAs<NamedDecl>(
"decl"))
56 diag(TypeDecl->getBeginLoc(),
"type defined here", DiagnosticIDs::Note);
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.