[clang-tidy] Redundant const specifier for variables that are already constexpr
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Imagine this:
```cpp
// foo.cpp
constexpr const int FOO = 10;
```
Since `constexpr` already implies `const`, appending additional `const` is redundant, we could simply write
```cpp
// foo.cpp
constexpr int FOO = 10;
```
We do a similar thing with [redundant-inline-specifier](https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-inline-specifier.html) for functions, since `constexpr` also implies `inline`, making the `inline` redundant.
We might need to be careful with pointers, for instance:
```cpp
// foo.cpp
constexpr const char* FOO = "Hello";
```
In this case, `const` is not redundant since `constexpr` implies `const` for the pointer but not the pointee. In fact, one might even appreciate a hint on this if const is missing.
https://godbolt.org/z/aenso7Td9
Contributor guide
Research direction
Start by reading the existing readability/redundant-inline-specifier check linked in the issue and use the foo.cpp examples as input cases. Pay particular attention to the constexpr pointer example, where const on the pointee is not redundant. Done means the check identifies redundant const on constexpr variables without incorrectly flagging required pointee qualification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100