[clang-tidy][NFC] Prefer static constexpr over static const where possible (#173406)
This commit is contained in:
parent
bf932867ac
commit
7bad288567
@ -157,7 +157,7 @@ template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> {
|
||||
};
|
||||
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> {
|
||||
// NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
|
||||
static const bool flow = false;
|
||||
static constexpr bool flow = false;
|
||||
};
|
||||
template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
|
||||
static void mapping(IO &IO, ClangTidyOptions::CustomCheckDiag &D) {
|
||||
@ -169,7 +169,7 @@ template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
|
||||
};
|
||||
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
|
||||
// NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
|
||||
static const bool flow = false;
|
||||
static constexpr bool flow = false;
|
||||
};
|
||||
template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
|
||||
static void mapping(IO &IO, ClangTidyOptions::CustomCheckValue &V) {
|
||||
@ -324,14 +324,6 @@ ClangTidyOptions ClangTidyOptions::merge(const ClangTidyOptions &Other,
|
||||
return Result;
|
||||
}
|
||||
|
||||
const char ClangTidyOptionsProvider::OptionsSourceTypeDefaultBinary[] =
|
||||
"clang-tidy binary";
|
||||
const char ClangTidyOptionsProvider::OptionsSourceTypeCheckCommandLineOption[] =
|
||||
"command-line option '-checks'";
|
||||
const char
|
||||
ClangTidyOptionsProvider::OptionsSourceTypeConfigCommandLineOption[] =
|
||||
"command-line option '-config'";
|
||||
|
||||
ClangTidyOptions
|
||||
ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
|
||||
ClangTidyOptions Result;
|
||||
|
||||
@ -170,9 +170,11 @@ struct ClangTidyOptions {
|
||||
/// Abstract interface for retrieving various ClangTidy options.
|
||||
class ClangTidyOptionsProvider {
|
||||
public:
|
||||
static const char OptionsSourceTypeDefaultBinary[];
|
||||
static const char OptionsSourceTypeCheckCommandLineOption[];
|
||||
static const char OptionsSourceTypeConfigCommandLineOption[];
|
||||
static constexpr char OptionsSourceTypeDefaultBinary[] = "clang-tidy binary";
|
||||
static constexpr char OptionsSourceTypeCheckCommandLineOption[] =
|
||||
"command-line option '-checks'";
|
||||
static constexpr char OptionsSourceTypeConfigCommandLineOption[] =
|
||||
"command-line option '-config'";
|
||||
|
||||
virtual ~ClangTidyOptionsProvider() = default;
|
||||
|
||||
|
||||
@ -33,10 +33,11 @@ namespace {
|
||||
AST_MATCHER(Type, isCharType) { return Node.isCharType(); }
|
||||
} // namespace
|
||||
|
||||
static const char DefaultStringLikeClasses[] = "::std::basic_string;"
|
||||
"::std::basic_string_view;"
|
||||
"::absl::string_view";
|
||||
static const char DefaultAbseilStringsMatchHeader[] = "absl/strings/match.h";
|
||||
static constexpr char DefaultStringLikeClasses[] = "::std::basic_string;"
|
||||
"::std::basic_string_view;"
|
||||
"::absl::string_view";
|
||||
static constexpr char DefaultAbseilStringsMatchHeader[] =
|
||||
"absl/strings/match.h";
|
||||
|
||||
static transformer::RewriteRuleWith<std::string>
|
||||
makeRewriteRule(ArrayRef<StringRef> StringLikeClassNames,
|
||||
|
||||
@ -348,7 +348,7 @@ DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) {
|
||||
}
|
||||
ArrayRef<std::pair<StringRef, StringRef>>
|
||||
UseRangesCheck::getFreeBeginEndMethods() const {
|
||||
static const std::pair<StringRef, StringRef> Refs[] = {
|
||||
static constexpr std::pair<StringRef, StringRef> Refs[] = {
|
||||
{"::std::begin", "::std::end"},
|
||||
{"::std::cbegin", "::std::cend"},
|
||||
{"::boost::range_adl_barrier::begin", "::boost::range_adl_barrier::end"},
|
||||
@ -359,7 +359,7 @@ UseRangesCheck::getFreeBeginEndMethods() const {
|
||||
}
|
||||
std::optional<UseRangesCheck::ReverseIteratorDescriptor>
|
||||
UseRangesCheck::getReverseDescriptor() const {
|
||||
static const std::pair<StringRef, StringRef> Refs[] = {
|
||||
static constexpr std::pair<StringRef, StringRef> Refs[] = {
|
||||
{"::std::rbegin", "::std::rend"},
|
||||
{"::std::crbegin", "::std::crend"},
|
||||
{"::boost::rbegin", "::boost::rend"},
|
||||
|
||||
@ -55,17 +55,17 @@ template <> struct OptionEnumMapping<modernize::VariableNamer::NamingStyle> {
|
||||
|
||||
namespace modernize {
|
||||
|
||||
static const char LoopNameArray[] = "forLoopArray";
|
||||
static const char LoopNameIterator[] = "forLoopIterator";
|
||||
static const char LoopNameReverseIterator[] = "forLoopReverseIterator";
|
||||
static const char LoopNamePseudoArray[] = "forLoopPseudoArray";
|
||||
static const char ConditionBoundName[] = "conditionBound";
|
||||
static const char InitVarName[] = "initVar";
|
||||
static const char BeginCallName[] = "beginCall";
|
||||
static const char EndCallName[] = "endCall";
|
||||
static const char EndVarName[] = "endVar";
|
||||
static const char DerefByValueResultName[] = "derefByValueResult";
|
||||
static const char DerefByRefResultName[] = "derefByRefResult";
|
||||
static constexpr char LoopNameArray[] = "forLoopArray";
|
||||
static constexpr char LoopNameIterator[] = "forLoopIterator";
|
||||
static constexpr char LoopNameReverseIterator[] = "forLoopReverseIterator";
|
||||
static constexpr char LoopNamePseudoArray[] = "forLoopPseudoArray";
|
||||
static constexpr char ConditionBoundName[] = "conditionBound";
|
||||
static constexpr char InitVarName[] = "initVar";
|
||||
static constexpr char BeginCallName[] = "beginCall";
|
||||
static constexpr char EndCallName[] = "endCall";
|
||||
static constexpr char EndVarName[] = "endVar";
|
||||
static constexpr char DerefByValueResultName[] = "derefByValueResult";
|
||||
static constexpr char DerefByRefResultName[] = "derefByRefResult";
|
||||
static const llvm::StringSet<> MemberNames{"begin", "cbegin", "rbegin",
|
||||
"crbegin", "end", "cend",
|
||||
"rend", "crend", "size"};
|
||||
|
||||
@ -33,8 +33,6 @@ static std::string getNewExprName(const CXXNewExpr *NewExpr,
|
||||
return WrittenName.str();
|
||||
}
|
||||
|
||||
const char MakeSmartPtrCheck::PointerType[] = "pointerType";
|
||||
|
||||
MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
|
||||
StringRef MakeSmartPtrFunctionName)
|
||||
: ClangTidyCheck(Name, Context),
|
||||
|
||||
@ -41,7 +41,7 @@ protected:
|
||||
/// Returns whether the C++ version is compatible with current check.
|
||||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
|
||||
|
||||
static const char PointerType[];
|
||||
static constexpr char PointerType[] = "pointerType";
|
||||
|
||||
private:
|
||||
utils::IncludeInserter Inserter;
|
||||
|
||||
@ -18,9 +18,11 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang::tidy::modernize {
|
||||
|
||||
static constexpr char AutoPtrTokenId[] = "AutoPrTokenId";
|
||||
static constexpr char AutoPtrOwnershipTransferId[] =
|
||||
"AutoPtrOwnershipTransferId";
|
||||
|
||||
namespace {
|
||||
static const char AutoPtrTokenId[] = "AutoPrTokenId";
|
||||
static const char AutoPtrOwnershipTransferId[] = "AutoPtrOwnershipTransferId";
|
||||
|
||||
/// Matches expressions that are lvalues.
|
||||
///
|
||||
|
||||
@ -21,10 +21,10 @@ using namespace clang::ast_matchers::internal;
|
||||
|
||||
namespace clang::tidy::modernize {
|
||||
|
||||
static const char IteratorDeclStmtId[] = "iterator_decl";
|
||||
static const char DeclWithNewId[] = "decl_new";
|
||||
static const char DeclWithCastId[] = "decl_cast";
|
||||
static const char DeclWithTemplateCastId[] = "decl_template";
|
||||
static constexpr char IteratorDeclStmtId[] = "iterator_decl";
|
||||
static constexpr char DeclWithNewId[] = "decl_new";
|
||||
static constexpr char DeclWithCastId[] = "decl_cast";
|
||||
static constexpr char DeclWithTemplateCastId[] = "decl_template";
|
||||
|
||||
static size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
|
||||
enum CharType { Space, Alpha, Punctuation };
|
||||
|
||||
@ -100,18 +100,18 @@ cxxMemberCallExprOnContainer(StringRef MethodName,
|
||||
on(hasTypeOrPointeeType(hasWantedType(ContainerNames))));
|
||||
}
|
||||
|
||||
static const auto DefaultContainersWithPushBack =
|
||||
static constexpr char DefaultContainersWithPushBack[] =
|
||||
"::std::vector; ::std::list; ::std::deque";
|
||||
static const auto DefaultContainersWithPush =
|
||||
static constexpr char DefaultContainersWithPush[] =
|
||||
"::std::stack; ::std::queue; ::std::priority_queue";
|
||||
static const auto DefaultContainersWithPushFront =
|
||||
static constexpr char DefaultContainersWithPushFront[] =
|
||||
"::std::forward_list; ::std::list; ::std::deque";
|
||||
static const auto DefaultSmartPointers =
|
||||
static constexpr char DefaultSmartPointers[] =
|
||||
"::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
|
||||
static const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
|
||||
static const auto DefaultTupleMakeFunctions =
|
||||
static constexpr char DefaultTupleTypes[] = "::std::pair; ::std::tuple";
|
||||
static constexpr char DefaultTupleMakeFunctions[] =
|
||||
"::std::make_pair; ::std::make_tuple";
|
||||
static const auto DefaultEmplacyFunctions =
|
||||
static constexpr char DefaultEmplacyFunctions[] =
|
||||
"vector::emplace_back; vector::emplace;"
|
||||
"deque::emplace; deque::emplace_front; deque::emplace_back;"
|
||||
"forward_list::emplace_after; forward_list::emplace_front;"
|
||||
|
||||
@ -18,7 +18,7 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang::tidy::modernize {
|
||||
|
||||
static const char SpecialFunction[] = "SpecialFunction";
|
||||
static constexpr char SpecialFunction[] = "SpecialFunction";
|
||||
|
||||
/// Finds all the named non-static fields of \p Record.
|
||||
static std::set<const FieldDecl *>
|
||||
|
||||
@ -41,8 +41,8 @@ AST_MATCHER(CXXMethodDecl, isSpecialFunction) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
static const char SpecialFunction[] = "SpecialFunction";
|
||||
static const char DeletedNotPublic[] = "DeletedNotPublic";
|
||||
static constexpr char SpecialFunction[] = "SpecialFunction";
|
||||
static constexpr char DeletedNotPublic[] = "DeletedNotPublic";
|
||||
|
||||
UseEqualsDeleteCheck::UseEqualsDeleteCheck(StringRef Name,
|
||||
ClangTidyContext *Context)
|
||||
|
||||
@ -30,7 +30,7 @@ AST_MATCHER(Type, sugaredNullptrType) {
|
||||
|
||||
} // namespace
|
||||
|
||||
static const char CastSequence[] = "sequence";
|
||||
static constexpr char CastSequence[] = "sequence";
|
||||
|
||||
/// Create a matcher that finds implicit casts as well as the head of a
|
||||
/// sequence of zero or more nested explicit casts that have an implicit cast
|
||||
|
||||
@ -152,7 +152,7 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
|
||||
|
||||
static const Signature SinglePivotFunc[] = {SinglePivotRange};
|
||||
|
||||
static const std::pair<ArrayRef<Signature>, ArrayRef<const char *>>
|
||||
static constexpr std::pair<ArrayRef<Signature>, ArrayRef<const char *>>
|
||||
AlgorithmNames[] = {{SingleRangeFunc, SingleRangeNames},
|
||||
{TwoRangeFunc, TwoRangeNames},
|
||||
{SinglePivotFunc, SinglePivotRangeNames}};
|
||||
@ -189,13 +189,13 @@ bool UseRangesCheck::isLanguageVersionSupported(
|
||||
}
|
||||
ArrayRef<std::pair<StringRef, StringRef>>
|
||||
UseRangesCheck::getFreeBeginEndMethods() const {
|
||||
static const std::pair<StringRef, StringRef> Refs[] = {
|
||||
static constexpr std::pair<StringRef, StringRef> Refs[] = {
|
||||
{"::std::begin", "::std::end"}, {"::std::cbegin", "::std::cend"}};
|
||||
return Refs;
|
||||
}
|
||||
std::optional<UseRangesCheck::ReverseIteratorDescriptor>
|
||||
UseRangesCheck::getReverseDescriptor() const {
|
||||
static const std::pair<StringRef, StringRef> Refs[] = {
|
||||
static constexpr std::pair<StringRef, StringRef> Refs[] = {
|
||||
{"::std::rbegin", "::std::rend"}, {"::std::crbegin", "::std::crend"}};
|
||||
return ReverseIteratorDescriptor{"std::views::reverse", "<ranges>", Refs,
|
||||
UseReversePipe};
|
||||
|
||||
@ -59,7 +59,7 @@ void UseTransparentFunctorsCheck::registerMatchers(MatchFinder *Finder) {
|
||||
this);
|
||||
}
|
||||
|
||||
static const StringRef Message = "prefer transparent functors '%0<>'";
|
||||
static constexpr StringRef Message = "prefer transparent functors '%0<>'";
|
||||
|
||||
template <typename T> static T getInnerTypeLocAs(TypeLoc Loc) {
|
||||
T Result;
|
||||
|
||||
@ -46,17 +46,17 @@ namespace clang::tidy::performance {
|
||||
// - ProtoVarDeclName: 'p' (as VarDecl).
|
||||
// - ProtoVarDeclStmtName: The entire 'SomeProto p;' statement (as DeclStmt).
|
||||
// - ProtoAddFieldCallName: 'p.add_xxx(i)' (as cxxMemberCallExpr).
|
||||
static const char LoopCounterName[] = "for_loop_counter";
|
||||
static const char LoopParentName[] = "loop_parent";
|
||||
static const char VectorVarDeclName[] = "vector_var_decl";
|
||||
static const char VectorVarDeclStmtName[] = "vector_var_decl_stmt";
|
||||
static const char PushBackOrEmplaceBackCallName[] = "append_call";
|
||||
static const char ProtoVarDeclName[] = "proto_var_decl";
|
||||
static const char ProtoVarDeclStmtName[] = "proto_var_decl_stmt";
|
||||
static const char ProtoAddFieldCallName[] = "proto_add_field";
|
||||
static const char LoopInitVarName[] = "loop_init_var";
|
||||
static const char LoopEndExprName[] = "loop_end_expr";
|
||||
static const char RangeLoopName[] = "for_range_loop";
|
||||
static constexpr char LoopCounterName[] = "for_loop_counter";
|
||||
static constexpr char LoopParentName[] = "loop_parent";
|
||||
static constexpr char VectorVarDeclName[] = "vector_var_decl";
|
||||
static constexpr char VectorVarDeclStmtName[] = "vector_var_decl_stmt";
|
||||
static constexpr char PushBackOrEmplaceBackCallName[] = "append_call";
|
||||
static constexpr char ProtoVarDeclName[] = "proto_var_decl";
|
||||
static constexpr char ProtoVarDeclStmtName[] = "proto_var_decl_stmt";
|
||||
static constexpr char ProtoAddFieldCallName[] = "proto_add_field";
|
||||
static constexpr char LoopInitVarName[] = "loop_init_var";
|
||||
static constexpr char LoopEndExprName[] = "loop_end_expr";
|
||||
static constexpr char RangeLoopName[] = "for_range_loop";
|
||||
|
||||
static ast_matchers::internal::Matcher<Expr> supportedContainerTypesMatcher() {
|
||||
return hasType(cxxRecordDecl(hasAnyName(
|
||||
|
||||
@ -15,10 +15,10 @@ using namespace clang::ast_matchers;
|
||||
namespace clang::tidy::readability {
|
||||
|
||||
static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
|
||||
static const bool IgnoreMacrosDefault = true;
|
||||
static constexpr bool IgnoreMacrosDefault = true;
|
||||
|
||||
static constexpr char StrictModeName[] = "StrictMode";
|
||||
static const bool StrictModeDefault = true;
|
||||
static constexpr bool StrictModeDefault = true;
|
||||
|
||||
AvoidReturnWithVoidValueCheck::AvoidReturnWithVoidValueCheck(
|
||||
StringRef Name, ClangTidyContext *Context)
|
||||
|
||||
@ -41,10 +41,11 @@ private:
|
||||
|
||||
} // namespace
|
||||
|
||||
static const char InterruptingStr[] = "interrupting";
|
||||
static const char WarningMessage[] = "do not use 'else' after '%0'";
|
||||
static const char WarnOnUnfixableStr[] = "WarnOnUnfixable";
|
||||
static const char WarnOnConditionVariablesStr[] = "WarnOnConditionVariables";
|
||||
static constexpr char InterruptingStr[] = "interrupting";
|
||||
static constexpr char WarningMessage[] = "do not use 'else' after '%0'";
|
||||
static constexpr char WarnOnUnfixableStr[] = "WarnOnUnfixable";
|
||||
static constexpr char WarnOnConditionVariablesStr[] =
|
||||
"WarnOnConditionVariables";
|
||||
|
||||
static const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
|
||||
if (!Node)
|
||||
|
||||
@ -152,7 +152,7 @@ struct CognitiveComplexity final {
|
||||
// to use is based of the combination of the CognitiveComplexity::Criteria.
|
||||
// It would be nice to have it in CognitiveComplexity struct, but then it is
|
||||
// not static.
|
||||
static const std::array<const StringRef, 4> Msgs = {{
|
||||
static constexpr std::array<StringRef, 4> Msgs = {{
|
||||
// B1 + B2 + B3
|
||||
"+%0, including nesting penalty of %1, nesting level increased to %2",
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang::tidy::readability {
|
||||
|
||||
static const char KDefaultTypes[] =
|
||||
static constexpr char KDefaultTypes[] =
|
||||
"::std::basic_string;::std::basic_string_view;::std::vector;::std::array;::"
|
||||
"std::span";
|
||||
|
||||
|
||||
@ -19,12 +19,13 @@ namespace optutils = clang::tidy::utils::options;
|
||||
|
||||
namespace clang::tidy::readability {
|
||||
|
||||
static const StringRef CompareMessage = "do not use 'compare' to test equality "
|
||||
"of strings; use the string equality "
|
||||
"operator instead";
|
||||
static constexpr StringRef CompareMessage =
|
||||
"do not use 'compare' to test equality of strings; use the string "
|
||||
"equality operator instead";
|
||||
|
||||
static const StringRef DefaultStringLikeClasses = "::std::basic_string;"
|
||||
"::std::basic_string_view";
|
||||
static constexpr StringRef DefaultStringLikeClasses =
|
||||
"::std::basic_string;"
|
||||
"::std::basic_string_view";
|
||||
|
||||
StringCompareCheck::StringCompareCheck(StringRef Name,
|
||||
ClangTidyContext *Context)
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
namespace clang::tidy::utils::options {
|
||||
|
||||
static const char StringsDelimiter[] = ";";
|
||||
static constexpr char StringsDelimiter[] = ";";
|
||||
|
||||
std::vector<StringRef> parseStringList(StringRef Option) {
|
||||
Option = Option.trim().trim(StringsDelimiter);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user