Skip to content

Commit 7a32e07

Browse files
committed
add ConstexprString option
1 parent 12cf4eb commit 7a32e07

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ void UseConstexprCheck::onEndOfTranslationUnit() {
908908
for (const Decl *D : Func->redecls())
909909
if (const auto *FDecl = llvm::dyn_cast<FunctionDecl>(D))
910910
Diag << FixItHint::CreateInsertion(FDecl->getInnerLocStart(),
911-
"constexpr ");
911+
ConstexprString + " ");
912912
}
913913
for (const auto &[Var, FuncCtx] : VariableMapping) {
914914
if (FuncCtx && getLangOpts().CPlusPlus23 && Var->isStaticLocal() &&
@@ -919,7 +919,8 @@ void UseConstexprCheck::onEndOfTranslationUnit() {
919919
auto Diag =
920920
diag(Var->getLocation(), "variable %0 can be declared 'constexpr'")
921921
<< Var << R
922-
<< FixItHint::CreateInsertion(Var->getInnerLocStart(), "constexpr ");
922+
<< FixItHint::CreateInsertion(Var->getInnerLocStart(),
923+
ConstexprString + " ");
923924
if (const std::optional<Token> ConstToken =
924925
utils::lexer::getQualifyingToken(
925926
tok::TokenKind::kw_const,
@@ -938,10 +939,12 @@ UseConstexprCheck::UseConstexprCheck(StringRef Name, ClangTidyContext *Context)
938939
: ClangTidyCheck(Name, Context),
939940
ConservativeLiteralType(Options.get("ConservativeLiteralType", true)),
940941
AddConstexprToMethodOfClassWithoutConstexprConstructor(Options.get(
941-
"AddConstexprToMethodOfClassWithoutConstexprConstructor", false)) {}
942+
"AddConstexprToMethodOfClassWithoutConstexprConstructor", false)),
943+
ConstexprString(Options.get("ConstexprString", "constexpr")) {}
942944
void UseConstexprCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
943945
Options.store(Opts, "ConservativeLiteralType", ConservativeLiteralType);
944946
Options.store(Opts, "AddConstexprToMethodOfClassWithoutConstexprConstructor",
945947
AddConstexprToMethodOfClassWithoutConstexprConstructor);
948+
Options.store(Opts, "ConstexprString", ConstexprString);
946949
}
947950
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class UseConstexprCheck : public ClangTidyCheck {
3434
private:
3535
const bool ConservativeLiteralType;
3636
const bool AddConstexprToMethodOfClassWithoutConstexprConstructor;
37+
const std::string ConstexprString;
3738
llvm::SmallPtrSet<const FunctionDecl *, 32> Functions;
3839
llvm::DenseMap<const VarDecl *, const FunctionDecl *> VariableMapping;
3940
};

clang-tools-extra/docs/clang-tidy/checks/modernize/use-constexpr.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ Options
3838
``constexpr`` to a member function is superfluous. This option controls if
3939
``constexpr`` should be added anyways. Default is ``false``.
4040

41+
.. option:: ConstexprString
42+
43+
The string to use to specify something as ``constexpr``, for example, a macro.
44+
Default is ``constexpr``.
45+

0 commit comments

Comments
 (0)