[clang-tidy] readability-use-std-min-max generates invalid code for string, where bare `size_type` is used
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
clang-tidy 22.1.8
```cpp
#include
void f(const std::string &s, unsigned &n) {
if (s.size() > n)
n = s.size();
}
```
`clang-tidy --checks=readability-use-std-min-max --fix a.cpp` rewrites the function body as follows
```cpp
n = std::max(s.size(), n);
```
which does not compile since `size_type` is unknown; the correct fix is
```cpp
n = std::max(s.size(), n);
// or std::string::size_type, or size_t?
```
Contributor guide
Research direction
Start with the clang-tidy readability-use-std-min-max check and reproduce the issue using the a.cpp example and the provided clang-tidy command. Trace how the replacement type is selected for s.size(), then verify the fix no longer emits bare size_type and that the resulting a.cpp compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100