Skip to content

Commit

Permalink
[clang-tidy][NFC] Fix modernize-return-braced-init-list findings
Browse files Browse the repository at this point in the history
Fix issues found by clang-tidy in clang-tidy source directory.
  • Loading branch information
PiotrZSL committed Aug 27, 2023
1 parent 9c857f2 commit ec5f4be
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 80 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ class ErrorReporter {
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);
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ class ClangTidyContext {
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) {
Expand Down
4 changes: 1 addition & 3 deletions clang-tools-extra/clang-tidy/ClangTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ ClangTidyCheckFactories::createChecksForLanguage(
return Checks;
}

ClangTidyOptions ClangTidyModule::getModuleOptions() {
return ClangTidyOptions();
}
ClangTidyOptions ClangTidyModule::getModuleOptions() { return {}; }

} // namespace clang::tidy
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/GlobList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */) {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ")")
Expand All @@ -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) + ")")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ struct OptionEnumMapping<
{bugprone::SignalHandlerCheck::AsyncSafeFunctionSetKind::POSIX,
"POSIX"},
};
return ArrayRef(Mapping);
return {Mapping};
}
};

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -80,7 +80,7 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) {
CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
llvm::StringRef(NewName));

return FixItHint();
return {};
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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") +
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
};

Expand All @@ -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};
}
};

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 9 additions & 11 deletions clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,24 @@ 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,
const TemplateSpecializationTypeLoc &EnableIf) {
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
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ FixItHint generateFixItHint(const ObjCPropertyDecl *Decl, NamingStyle Style) {
llvm::StringRef(NewName));
}
}
return FixItHint();
return {};
}

std::string validPropertyNameRegex(bool UsedInMatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ OptionEnumMapping<
"Camel_Snake_Case"},
{readability::IdentifierNamingCheck::CT_CamelSnakeBack,
"camel_Snake_Back"}};
return llvm::ArrayRef(Mapping);
return {Mapping};
}

template <>
Expand All @@ -62,7 +62,7 @@ struct OptionEnumMapping<
{HungarianPrefixType::HPT_On, "On"},
{HungarianPrefixType::HPT_LowerCase, "LowerCase"},
{HungarianPrefixType::HPT_CamelCase, "CamelCase"}};
return llvm::ArrayRef(Mapping);
return {Mapping};
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
return "true";
}

return StringRef();
return {};
}

void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
8 changes: 2 additions & 6 deletions clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ class ExceptionAnalyzer {
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.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("->");
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ec5f4be

Please sign in to comment.