[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

Sean McBride via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 1 13:18:34 PDT 2025


seanm wrote:

I tried with [ITK](https://github.com/InsightSoftwareConsortium/ITK/) and the resulting transformation did not compile.

Many changes were of this form:

```diff
-    const double     Max = 1.0 - Min;
+    constexpr  double     Max = 1.0 - Min;
```

Which is great, though notice the double space after `constexpr` for some reason.

Other changes were like this:

```diff
-  const auto check = [](const auto & ptr) { EXPECT_THROW(itk::Deref(ptr), itk::DerefError); };
+  constexpr const auto check = [](auto & ptr) { EXPECT_THROW(itk::Deref(ptr), itk::DerefError); };
```

I'm no C++ expert, but is it right to have both `const` ***and*** `constexpr` here?

Also, I was surprised to see the 2nd const *removed*. And this removal generates one of the many compiler errors.

Still, this is looking like it'll be great!

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


More information about the cfe-commits mailing list