10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
18 Finder->addMatcher(staticAssertDecl().bind(
"static_assert"),
this);
22 const auto *MatchedDecl =
23 Result.Nodes.getNodeAs<StaticAssertDecl>(
"static_assert");
24 const auto *AssertMessage =
25 dyn_cast_if_present<StringLiteral>(MatchedDecl->getMessage());
27 SourceLocation
Loc = MatchedDecl->getLocation();
29 if (!AssertMessage || AssertMessage->getLength() ||
30 AssertMessage->getBeginLoc().isMacroID() ||
Loc.isMacroID())
34 "use unary 'static_assert' when the string literal is an empty string")
35 << FixItHint::CreateRemoval(AssertMessage->getSourceRange());
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.