<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138566>138566</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Different behavior for comparison of integer comparison
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
StefanoD
</td>
</tr>
</table>
<pre>
clang-version: 20.1.0
compiler flags: -Wall -O1 -Wextra -Wshadow -Weffc++ -Wno-long-long -pedantic -pedantic-errors -std=c++14
When two variables are multiplied, which leads to integer promotion and the result is not stored into a variable, following example [compiles without problems](https://godbolt.org/z/69v43z9nx):
```cpp
#include <cstdint>
bool square_less_than_method_A(uint16_t a, uint64_t b) {
// a * a does integer promotion
return (a * a < b);
}
int main(int, char**) {
return 0;
}
```
Assigning the product to a variable, results in a [compile error](https://godbolt.org/z/sMso378va):
```cpp
#include <cstdint>
bool square_less_than_method_B(uint16_t a, uint64_t b) {
const auto a_squared = a * a;
return a_squared < b;
}
int main(int, char**) {
return 0;
}
```
```
<source>:5:22: warning: comparison of integers of different signs: 'const int' and 'uint64_t' (aka 'unsigned long') [-Wsign-compare]
5 | return a_squared < b;
| ~~~~~~~~~ ^ ~
```
The second example should also compile as `a*a` is always positive. So, I get here a false-positive warning.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VU2PozgQ_TWVS4kIbD6SAweSTKQ9rPYwK-UYObgI3jU2a5ukZw7z21eGpKdne6WZS0co2ObxXPVeuRDeq6shqqHYQXFYiSn01tWfA3XC2MPqYuWXutXCXJMbOa-sAd4gS9fZOoW0ae0wKk0OOy2uPj5KTkJrTP7IMDnRS3ACk5PvhbT3uNB1LbAdsB0mJ2MTbc11_sNkJClMUO33UULOWecx8UECPzxezHJIG0ibU08Gw93iTTglLpo8Ckc4TDqoUSuSwPZ471XboyYhPQaLygS6ksPR2cEGZQ0KIzH0hI78pAMqj8YG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