-Wtautological-constant-out-of-range-compare generates counterproductive warning
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Take into account the following dummy code
```c++
#include
class Foo
{
public:
void setSize(unsigned int size) {
std::vector bitmaps;
if (size > bitmaps.max_size()) {
return;
}
bitmaps.resize(size);
}
};
int main(int argc, char **) {
Foo f;
f.setSize(argc);
return 0;
}
```
We run against clang it will say
`warning: result of comparison of constant 2305843009213693951 with expression of type 'unsigned int' is always false [-Wtautological-constant-out-of-range-compare]`
on the
`if (size > bitmaps.max_size()) {`
as seen in https://godbolt.org/z/Yfrexofh7
Which would lead one to think "ok, let's remove the check, it's useless, clang told me it will always be false"
But then you run it in a 32 bits machine and you realize the check is actually useful [because the vector max size is now much smaller] and the warning is gone as seen in https://godbolt.org/z/rvz8evb19
Contributor guide
Research direction
No repository file or test is named. Start by reproducing the C++ example with Clang on the 64-bit and 32-bit Godbolt links, comparing the warning at the max_size() check; done should mean the diagnostic no longer encourages removing a check that remains useful on another target.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100