[clang-tools-extra] [clang-tidy] Add modernize-use-constexpr check (PR #182015)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 18 05:05:01 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.h clang-tools-extra/test/clang-tidy/checkers/modernize/use-constexpr.cpp clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp
index 7bf983e45..a63693e5a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp
@@ -1,4 +1,5 @@
-//===--- UseConstexprCheck.cpp - clang-tidy --------------------------------===//
+//===--- UseConstexprCheck.cpp - clang-tidy
+//--------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -90,8 +91,7 @@ void UseConstexprCheck::check(const MatchFinder::MatchResult &Result) {
   while ((Pos = DeclText.find("const", Pos)) != StringRef::npos) {
     // Make sure it's not part of 'constexpr' or 'consteval' etc.
     const size_t End = Pos + 5;
-    const bool WordStart =
-        (Pos == 0 || !isAlphanumeric(DeclText[Pos - 1]));
+    const bool WordStart = (Pos == 0 || !isAlphanumeric(DeclText[Pos - 1]));
     const bool WordEnd =
         (End >= DeclText.size() || !isAlphanumeric(DeclText[End]));
     if (WordStart && WordEnd) {
@@ -105,12 +105,10 @@ void UseConstexprCheck::check(const MatchFinder::MatchResult &Result) {
     diag(VD->getLocation(), "variable %0 can be declared 'constexpr'")
         << VD
         << FixItHint::CreateReplacement(
-               CharSourceRange::getTokenRange(ConstLoc, ConstLoc),
-               "constexpr");
+               CharSourceRange::getTokenRange(ConstLoc, ConstLoc), "constexpr");
   } else {
     // Couldn't find 'const' token; emit diagnostic without fix-it.
-    diag(VD->getLocation(), "variable %0 can be declared 'constexpr'")
-        << VD;
+    diag(VD->getLocation(), "variable %0 can be declared 'constexpr'") << VD;
   }
 }
 
diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.h b/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.h
index 994155905..55106c711 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.h
@@ -1,4 +1,5 @@
-//===--- UseConstexprCheck.h - clang-tidy ------------------------*- C++ -*-===//
+//===--- UseConstexprCheck.h - clang-tidy ------------------------*- C++
+//-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

``````````

</details>


https://github.com/llvm/llvm-project/pull/182015


More information about the cfe-commits mailing list