[clang-tidy][NFC] Fix modernize-return-braced-init-list findings

Fix issues found by clang-tidy in clang-tidy source directory.
This commit is contained in:
Piotr Zegar 2023-08-26 18:35:54 +00:00
parent 9c857f2151
commit ec5f4be452
28 changed files with 68 additions and 80 deletions

View File

@ -242,11 +242,11 @@ public:
private:
SourceLocation getLocation(StringRef FilePath, unsigned Offset) {
if (FilePath.empty())
return SourceLocation();
return {};
auto File = SourceMgr.getFileManager().getFile(FilePath);
if (!File)
return SourceLocation();
return {};
FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);

View File

@ -212,11 +212,11 @@ public:
using DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string>;
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID,
SourceLocation Loc) {
return DiagLevelAndFormatString(
return {
static_cast<DiagnosticIDs::Level>(
DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)),
std::string(
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)));
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID))};
}
void setOptionsCollector(llvm::StringSet<> *Collector) {

View File

@ -46,8 +46,6 @@ ClangTidyCheckFactories::createChecksForLanguage(
return Checks;
}
ClangTidyOptions ClangTidyModule::getModuleOptions() {
return ClangTidyOptions();
}
ClangTidyOptions ClangTidyModule::getModuleOptions() { return {}; }
} // namespace clang::tidy

View File

@ -39,7 +39,7 @@ static llvm::Regex consumeGlob(StringRef &GlobList) {
RegexText.push_back(C);
}
RegexText.push_back('$');
return llvm::Regex(RegexText);
return {RegexText};
}
GlobList::GlobList(StringRef Globs, bool KeepNegativeGlobs /* =true */) {

View File

@ -278,7 +278,7 @@ std::string rewriteExprFromNumberToDuration(
return *MaybeRewrite;
if (isLiteralZero(Result, RootNode))
return std::string("absl::ZeroDuration()");
return {"absl::ZeroDuration()"};
return (llvm::Twine(getDurationFactoryForScale(Scale)) + "(" +
simplifyDurationFactoryArg(Result, RootNode) + ")")
@ -296,7 +296,7 @@ std::string rewriteExprFromNumberToTime(
return *MaybeRewrite;
if (isLiteralZero(Result, RootNode))
return std::string("absl::UnixEpoch()");
return {"absl::UnixEpoch()"};
return (llvm::Twine(getTimeFactoryForScale(Scale)) + "(" +
tooling::fixit::getText(RootNode, *Result.Context) + ")")

View File

@ -235,7 +235,7 @@ struct OptionEnumMapping<
{bugprone::SignalHandlerCheck::AsyncSafeFunctionSetKind::POSIX,
"POSIX"},
};
return ArrayRef(Mapping);
return {Mapping};
}
};

View File

@ -269,7 +269,7 @@ template <> struct OptionEnumMapping<concurrency::MtUnsafeCheck::FunctionSet> {
Mapping[] = {{concurrency::MtUnsafeCheck::FunctionSet::Posix, "posix"},
{concurrency::MtUnsafeCheck::FunctionSet::Glibc, "glibc"},
{concurrency::MtUnsafeCheck::FunctionSet::Any, "any"}};
return ArrayRef(Mapping);
return {Mapping};
}
};

View File

@ -83,13 +83,13 @@ struct DenseMapInfo<
clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId;
static inline ClassDefId getEmptyKey() {
return ClassDefId(DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
"EMPTY");
return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
"EMPTY"};
}
static inline ClassDefId getTombstoneKey() {
return ClassDefId(DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
"TOMBSTONE");
return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
"TOMBSTONE"};
}
static unsigned getHashValue(ClassDefId Val) {

View File

@ -38,7 +38,7 @@ static SourceRange findToken(const SourceManager &Sources,
SourceLocation StartLoc, SourceLocation EndLoc,
bool (*Pred)(const Token &)) {
if (StartLoc.isMacroID() || EndLoc.isMacroID())
return SourceRange();
return {};
FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
StringRef Buf = Sources.getBufferData(File);
const char *StartChar = Sources.getCharacterData(StartLoc);
@ -50,11 +50,11 @@ static SourceRange findToken(const SourceManager &Sources,
if (Pred(Tok)) {
Token NextTok;
Lex.LexFromRawLexer(NextTok);
return SourceRange(Tok.getLocation(), NextTok.getLocation());
return {Tok.getLocation(), NextTok.getLocation()};
}
} while (Tok.isNot(tok::eof) && Tok.getLocation() < EndLoc);
return SourceRange();
return {};
}
static bool declIsStdInitializerList(const NamedDecl *D) {

View File

@ -49,7 +49,7 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) {
// otherwise the check cannot determine the appropriate function name prefix
// to use.
if (Decl->getStorageClass() != SC_Static)
return FixItHint();
return {};
StringRef Name = Decl->getName();
std::string NewName = Decl->getName().str();
@ -80,7 +80,7 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) {
CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
llvm::StringRef(NewName));
return FixItHint();
return {};
}
} // namespace

View File

@ -26,7 +26,7 @@ FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
if (IsConst && (Decl->getStorageClass() != SC_Static)) {
// No fix available if it is not a static constant, since it is difficult
// to determine the proper fix in this case.
return FixItHint();
return {};
}
char FC = Decl->getName()[0];
@ -35,14 +35,14 @@ FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
// is a single-character variable, since it is difficult to determine the
// proper fix in this case. Users should create a proper variable name by
// their own.
return FixItHint();
return {};
}
char SC = Decl->getName()[1];
if ((FC == 'k' || FC == 'g') && !llvm::isAlpha(SC)) {
// No fix available if the prefix is correct but the second character is
// not alphabetical, since it is difficult to determine the proper fix in
// this case.
return FixItHint();
return {};
}
auto NewName = (IsConst ? "k" : "g") +

View File

@ -141,7 +141,7 @@ SourceLocation StaticAssertCheck::getLastParenLoc(const ASTContext *ASTCtx,
std::optional<llvm::MemoryBufferRef> Buffer =
SM.getBufferOrNone(SM.getFileID(AssertLoc));
if (!Buffer)
return SourceLocation();
return {};
const char *BufferPos = SM.getCharacterData(AssertLoc);
@ -152,7 +152,7 @@ SourceLocation StaticAssertCheck::getLastParenLoc(const ASTContext *ASTCtx,
// assert first left parenthesis
if (Lexer.LexFromRawLexer(Token) || Lexer.LexFromRawLexer(Token) ||
!Token.is(tok::l_paren))
return SourceLocation();
return {};
unsigned int ParenCount = 1;
while (ParenCount && !Lexer.LexFromRawLexer(Token)) {

View File

@ -38,7 +38,7 @@ template <> struct OptionEnumMapping<modernize::Confidence::Level> {
Mapping[] = {{modernize::Confidence::CL_Reasonable, "reasonable"},
{modernize::Confidence::CL_Safe, "safe"},
{modernize::Confidence::CL_Risky, "risky"}};
return ArrayRef(Mapping);
return {Mapping};
}
};
@ -51,7 +51,7 @@ template <> struct OptionEnumMapping<modernize::VariableNamer::NamingStyle> {
{modernize::VariableNamer::NS_CamelBack, "camelBack"},
{modernize::VariableNamer::NS_LowerCase, "lower_case"},
{modernize::VariableNamer::NS_UpperCase, "UPPER_CASE"}};
return ArrayRef(Mapping);
return {Mapping};
}
};
@ -465,7 +465,7 @@ static StringRef getStringFromRange(SourceManager &SourceMgr,
SourceRange Range) {
if (SourceMgr.getFileID(Range.getBegin()) !=
SourceMgr.getFileID(Range.getEnd())) {
return StringRef(); // Empty string.
return {}; // Empty string.
}
return Lexer::getSourceText(CharSourceRange(Range, true), SourceMgr,

View File

@ -199,14 +199,13 @@ getConditionRange(ASTContext &Context,
const SourceManager &SM = Context.getSourceManager();
if (EnableIf.getNumArgs() > 1) {
TemplateArgumentLoc NextArg = EnableIf.getArgLoc(1);
return SourceRange(
EnableIf.getLAngleLoc().getLocWithOffset(1),
utils::lexer::findPreviousTokenKind(NextArg.getSourceRange().getBegin(),
SM, LangOpts, tok::comma));
return {EnableIf.getLAngleLoc().getLocWithOffset(1),
utils::lexer::findPreviousTokenKind(
NextArg.getSourceRange().getBegin(), SM, LangOpts, tok::comma)};
}
return SourceRange(EnableIf.getLAngleLoc().getLocWithOffset(1),
getRAngleFileLoc(SM, EnableIf));
return {EnableIf.getLAngleLoc().getLocWithOffset(1),
getRAngleFileLoc(SM, EnableIf)};
}
static SourceRange getTypeRange(ASTContext &Context,
@ -214,11 +213,10 @@ static SourceRange getTypeRange(ASTContext &Context,
TemplateArgumentLoc Arg = EnableIf.getArgLoc(1);
const LangOptions &LangOpts = Context.getLangOpts();
const SourceManager &SM = Context.getSourceManager();
return SourceRange(
utils::lexer::findPreviousTokenKind(Arg.getSourceRange().getBegin(), SM,
LangOpts, tok::comma)
.getLocWithOffset(1),
getRAngleFileLoc(SM, EnableIf));
return {utils::lexer::findPreviousTokenKind(Arg.getSourceRange().getBegin(),
SM, LangOpts, tok::comma)
.getLocWithOffset(1),
getRAngleFileLoc(SM, EnableIf)};
}
// Returns the original source text of the second argument of a call to

View File

@ -85,8 +85,7 @@ parseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) {
}
static StringRef getText(const Token &Tok, const SourceManager &Sources) {
return StringRef(Sources.getCharacterData(Tok.getLocation()),
Tok.getLength());
return {Sources.getCharacterData(Tok.getLocation()), Tok.getLength()};
}
void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {

View File

@ -52,7 +52,7 @@ FixItHint generateFixItHint(const ObjCPropertyDecl *Decl, NamingStyle Style) {
llvm::StringRef(NewName));
}
}
return FixItHint();
return {};
}
std::string validPropertyNameRegex(bool UsedInMatcher) {

View File

@ -18,8 +18,7 @@ namespace clang::tidy::readability {
namespace {
SourceRange getTypeRange(const ParmVarDecl &Param) {
return SourceRange(Param.getBeginLoc(),
Param.getLocation().getLocWithOffset(-1));
return {Param.getBeginLoc(), Param.getLocation().getLocWithOffset(-1)};
}
} // namespace

View File

@ -159,27 +159,27 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S,
const ASTContext *Context) {
// Skip macros.
if (S->getBeginLoc().isMacroID())
return SourceLocation();
return {};
SourceLocation CondEndLoc = S->getCond()->getEndLoc();
if (const DeclStmt *CondVar = S->getConditionVariableDeclStmt())
CondEndLoc = CondVar->getEndLoc();
if (!CondEndLoc.isValid()) {
return SourceLocation();
return {};
}
SourceLocation PastCondEndLoc =
Lexer::getLocForEndOfToken(CondEndLoc, 0, SM, Context->getLangOpts());
if (PastCondEndLoc.isInvalid())
return SourceLocation();
return {};
SourceLocation RParenLoc =
forwardSkipWhitespaceAndComments(PastCondEndLoc, SM, Context);
if (RParenLoc.isInvalid())
return SourceLocation();
return {};
tok::TokenKind TokKind = getTokenKind(RParenLoc, SM, Context);
if (TokKind != tok::r_paren)
return SourceLocation();
return {};
return RParenLoc;
}

View File

@ -47,7 +47,7 @@ OptionEnumMapping<
"Camel_Snake_Case"},
{readability::IdentifierNamingCheck::CT_CamelSnakeBack,
"camel_Snake_Back"}};
return llvm::ArrayRef(Mapping);
return {Mapping};
}
template <>
@ -62,7 +62,7 @@ struct OptionEnumMapping<
{HungarianPrefixType::HPT_On, "On"},
{HungarianPrefixType::HPT_LowerCase, "LowerCase"},
{HungarianPrefixType::HPT_CamelCase, "CamelCase"}};
return llvm::ArrayRef(Mapping);
return {Mapping};
}
};

View File

@ -170,7 +170,7 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
return "true";
}
return StringRef();
return {};
}
void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,

View File

@ -43,7 +43,7 @@ static SourceLocation findStartOfIndirection(SourceLocation Start,
while (Indirections-- != 0) {
Start = findPreviousAnyTokenKind(Start, SM, LangOpts, tok::star, tok::amp);
if (Start.isInvalid() || Start.isMacroID())
return SourceLocation();
return {};
}
return Start;
}

View File

@ -31,9 +31,7 @@
using namespace clang::tooling;
using namespace llvm;
static cl::desc desc(StringRef description) {
return cl::desc(description.ltrim());
}
static cl::desc desc(StringRef description) { return {description.ltrim()}; }
static cl::OptionCategory ClangTidyCategory("clang-tidy options");

View File

@ -38,12 +38,8 @@ public:
class ExceptionInfo {
public:
using Throwables = llvm::SmallSet<const Type *, 2>;
static ExceptionInfo createUnknown() {
return ExceptionInfo(State::Unknown);
}
static ExceptionInfo createNonThrowing() {
return ExceptionInfo(State::Throwing);
}
static ExceptionInfo createUnknown() { return {State::Unknown}; }
static ExceptionInfo createNonThrowing() { return {State::Throwing}; }
/// By default the exception situation is unknown and must be
/// clarified step-wise.

View File

@ -253,7 +253,7 @@ std::string formatDereference(const Expr &ExprNode, const ASTContext &Context) {
StringRef Text = tooling::fixit::getText(ExprNode, Context);
if (Text.empty())
return std::string();
return {};
// Remove remaining '->' from overloaded operator call
Text.consume_back("->");

View File

@ -230,6 +230,6 @@ OptionEnumMapping<utils::IncludeSorter::IncludeStyle>::getEnumMapping() {
Mapping[] = {{utils::IncludeSorter::IS_LLVM, "llvm"},
{utils::IncludeSorter::IS_Google, "google"},
{utils::IncludeSorter::IS_Google_ObjC, "google-objc"}};
return ArrayRef(Mapping);
return {Mapping};
}
} // namespace clang::tidy

View File

@ -47,11 +47,11 @@ SourceLocation findPreviousTokenStart(SourceLocation Start,
const SourceManager &SM,
const LangOptions &LangOpts) {
if (Start.isInvalid() || Start.isMacroID())
return SourceLocation();
return {};
SourceLocation BeforeStart = Start.getLocWithOffset(-1);
if (BeforeStart.isInvalid() || BeforeStart.isMacroID())
return SourceLocation();
return {};
return Lexer::GetBeginningOfToken(BeforeStart, SM, LangOpts);
}
@ -61,16 +61,16 @@ SourceLocation findPreviousTokenKind(SourceLocation Start,
const LangOptions &LangOpts,
tok::TokenKind TK) {
if (Start.isInvalid() || Start.isMacroID())
return SourceLocation();
return {};
while (true) {
SourceLocation L = findPreviousTokenStart(Start, SM, LangOpts);
if (L.isInvalid() || L.isMacroID())
return SourceLocation();
return {};
Token T;
if (Lexer::getRawToken(L, T, SM, LangOpts, /*IgnoreWhiteSpace=*/true))
return SourceLocation();
return {};
if (T.is(TK))
return T.getLocation();
@ -230,7 +230,7 @@ static SourceLocation getSemicolonAfterStmtEndLoc(const SourceLocation &EndLoc,
if (NextTok && NextTok->is(tok::TokenKind::semi))
return NextTok->getLocation();
return SourceLocation();
return {};
}
SourceLocation getUnifiedEndLoc(const Stmt &S, const SourceManager &SM,

View File

@ -46,16 +46,16 @@ SourceLocation findPreviousAnyTokenKind(SourceLocation Start,
const LangOptions &LangOpts,
TokenKind TK, TokenKinds... TKs) {
if (Start.isInvalid() || Start.isMacroID())
return SourceLocation();
return {};
while (true) {
SourceLocation L = findPreviousTokenStart(Start, SM, LangOpts);
if (L.isInvalid() || L.isMacroID())
return SourceLocation();
return {};
Token T;
// Returning 'true' is used to signal failure to retrieve the token.
if (Lexer::getRawToken(L, T, SM, LangOpts, /*IgnoreWhiteSpace=*/true))
return SourceLocation();
return {};
if (T.isOneOf(TK, TKs...))
return T.getLocation();
@ -74,7 +74,7 @@ SourceLocation findNextAnyTokenKind(SourceLocation Start,
Lexer::findNextToken(Start, SM, LangOpts);
if (!CurrentToken)
return SourceLocation();
return {};
Token PotentialMatch = *CurrentToken;
if (PotentialMatch.isOneOf(TK, TKs...))
@ -84,7 +84,7 @@ SourceLocation findNextAnyTokenKind(SourceLocation Start,
// the loop, otherwise we will get infinite loop (findNextToken will return
// eof on eof).
if (PotentialMatch.is(tok::eof))
return SourceLocation();
return {};
Start = PotentialMatch.getLastLoc();
}
}

View File

@ -31,13 +31,13 @@ struct DenseMapInfo<clang::tidy::RenamerClangTidyCheck::NamingCheckId> {
using NamingCheckId = clang::tidy::RenamerClangTidyCheck::NamingCheckId;
static inline NamingCheckId getEmptyKey() {
return NamingCheckId(DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
"EMPTY");
return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
"EMPTY"};
}
static inline NamingCheckId getTombstoneKey() {
return NamingCheckId(DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
"TOMBSTONE");
return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
"TOMBSTONE"};
}
static unsigned getHashValue(NamingCheckId Val) {