[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)
Sean McBride via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 2 13:11:37 PDT 2025
seanm wrote:
I've tried another project: [opencv](https://github.com/opencv/opencv) and the result also fails to compile.
One case I think is because two variables are declared together. i.e.:
```
int foo, bar;
```
instead of:
```
int foo;
int bar;
```
Concretely:
```c++
const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" },
* const btype = borderMap[borderType & ~BORDER_ISOLATED];
```
Got changed to:
```
constexpr const char * borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" },
* const btype = borderMap[borderType & ~BORDER_ISOLATED];
```
which is fine for `borderMap` but not for `btype`.
Resulting in:
```
/Users/sean/external/opencv/modules/imgproc/src/filter.dispatch.cpp:757:17: error: constexpr variable 'btype' must be initialized by a constant expression
757 | * const btype = borderMap[borderType & ~BORDER_ISOLATED];
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
https://github.com/llvm/llvm-project/pull/146553
More information about the cfe-commits
mailing list