10#include "clang/AST/ASTContext.h"
11#include "clang/AST/Decl.h"
12#include "clang/AST/Expr.h"
13#include "clang/AST/Type.h"
14#include "clang/AST/TypeLoc.h"
15#include "clang/ASTMatchers/ASTMatchFinder.h"
16#include "clang/ASTMatchers/ASTMatchers.h"
23AST_MATCHER(InitListExpr, isSingleElementBracedList) {
24 return Node.isExplicit() && Node.getNumInits() == 1;
28 return Node.getBeginLoc().isMacroID() || Node.getEndLoc().isMacroID();
32 const ConstantArrayType *CAT =
33 Finder->getASTContext().getAsConstantArrayType(Node.getType());
34 return CAT && CAT->getElementType()->isScalarType();
40 return Node.getSizeExpr() ==
nullptr;
46 initListExpr(hasScalarArrayType(), isSingleElementBracedList(),
47 hasInit(0, ignoringParenImpCasts(integerLiteral(equals(0)))),
49 unless(hasAncestor(cxxStdInitializerListExpr())),
50 unless(hasParent(varDecl(
51 hasTypeLoc(arrayTypeLoc(hasDeducedArrayBound()))))))
57 const MatchFinder::MatchResult &Result) {
58 const auto *ILE = Result.Nodes.getNodeAs<InitListExpr>(
"init");
59 const SourceRange Range = ILE->getSourceRange();
60 diag(Range.getBegin(),
61 "redundant zero initializer; replace with empty braces")
62 << FixItHint::CreateReplacement(Range,
"{}");
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
AST_MATCHER(BinaryOperator, isRelationalOperator)