[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 1 14:46:00 PDT 2025
5chmidti 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.
The reason is that when inserting, I add a `constexpr ` with a trailing space, but when it is found, also remove the `const` token without its corresponding space. This will have to be fixed by running clang-format; we have a few of these additional whitespaces in some checks.
> 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.
Eh... yeah. The range I passed to the `getQualifyingToken` function was too big and included more than it needed. It's fixed now, and I've added a test for it.
> Still, this is looking like it'll be great!
Thanks, and thank you very much for trying it out. My current setup is limited in what I can test outside the LLVM codebase.
https://github.com/llvm/llvm-project/pull/146553
More information about the cfe-commits
mailing list