Issue |
89661
|
Summary |
[compiler warning]: comparison of integers of different signs: 'const int' and 'const unsigned long
|
Labels |
new issue
|
Assignees |
|
Reporter |
hiraditya
|
Comparing `0` with uint64_t value results in compiler warning. Does it make sense?
```cpp
#include<cstdint>
#include<cassert>
#include<string>
template <typename T1, typename T2>
std::string CmpHelperOpFailure(const char* expr1, const char* expr2,
const T1& val1, const T2& val2,
const char* op) {
return "failed";
}
#define GTEST_IMPL_CMP_HELPER_(op_name, op) \
template <typename T1, typename T2> \
std::string CmpHelper##op_name(const char* expr1, const char* expr2, \
const T1& val1, const T2& val2) { \
if (val1 op val2) { \
return "PASS"; \
} else { \
return CmpHelperOpFailure(expr1, expr2, val1, val2, #op); \
} \
}
GTEST_IMPL_CMP_HELPER_(NE, !=)
#define ASSERT_PRED_FORMAT2(Fun, val1, val2) Fun(#val1, #val2, val1, val2)
#define GTEST_ASSERT_NE(val1, val2) \
ASSERT_PRED_FORMAT2(CmpHelperNE, val1, val2)
#define ASSERT_NE(Op1, Op2) GTEST_ASSERT_NE(Op1, Op2)
uint64_t bar() {
return 100;
}
int foo(uint64_t l) {
ASSERT_NE(0, bar());
return 0;
}
```
$ clang++ -Wsign-compare test.cpp
```
<source>:24:28: error: comparison of integers of different signs: 'const int' and 'const unsigned long' [-Werror,-Wsign-compare]
24 | GTEST_IMPL_CMP_HELPER_(NE, !=)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
<source>:17:14: note: expanded from macro 'GTEST_IMPL_CMP_HELPER_'
17 | if (val1 op val2) { \
| ~~~~ ^ ~~~~
<source>:39:5: note: in instantiation of function template specialization 'CmpHelperNE<int, unsigned long>' requested here
39 | ASSERT_NE(0, bar());
| ^
<source>:32:29: note: expanded from macro 'ASSERT_NE'
32 | #define ASSERT_NE(Op1, Op2) GTEST_ASSERT_NE(Op1, Op2)
| ^
<source>:30:23: note: expanded from macro 'GTEST_ASSERT_NE'
30 | ASSERT_PRED_FORMAT2(CmpHelperNE, val1, val2)
| ^
1 error generated.
Compiler returned: 1
```
https://godbolt.org/z/qxPEd986n
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs