| Issue |
177861
|
| Summary |
-Wtautological-constant-out-of-range-compare generates counterproductive warning
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
tsdgeos
|
Take into account the following dummy code
```
#include <vector>
class Foo
{
public:
void setSize(unsigned int size) {
std::vector<unsigned int> 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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs