为什么在相同大小的功能参数中隐式转换不会发出警告
Why do implicit conversions in function parameters of same size not throw a warning?
请参阅该示例:
//test.cpp
#include <iostream>
void test(unsigned int i, int j) {
std::cout << i << " " << j << std::endl;
}
int main() {
test(-1, -1);
int x = -1;
test(x,x);
return 0;
}
with:
$ g++ -Wall -Wextra -Wpedantic test.cpp:
4294967295 -1
4294967295 -1
为什么海湾合作杂志让那个滑倒?并且是否可以选择检测这种隐式转换?
欢呼
之前已经回答过。原因之一是因为C允许它,而C 则是向后兼容的。一些编译器会警告,尽管我在GCC 5.2上进行了测试,但它没有打开警告的选择。
请参阅:为什么C 允许从int到未签名的int?
的隐式转换#刚从其他答案之一中找到您需要添加-wsign -conversion标志。似乎是-wall应该这样做,但不做。
是的,我找到了它。误以为(-wall -wextra -w -wpedantic -wconversion(将涵盖所有内容。但是在
中https://gcc.gnu.org/onlinedocs/gcc/warning-options.html
缺失的标志为: -wsign-conversion
相关文章:
- 将无符号转换为复杂<int>原因符号转换警告
- 为什么在 c++ 中索引字符串会发出隐式转换警告?
- C++:禁用隐式转换警告
- 意外 (IMO) 常量转换警告
- C++:禁用 CMake 中的旧样式转换警告
- 键入从 DWORD 到 64 位指针的强制转换警告
- 隐式转换警告 int 到 int-looklike
- 移植到 64 位时如何避免size_t int 强制转换警告?
- 构造函数中的 C4267 转换警告 - 无法修复过载?
- 如何修复隐式转换警告?
- 为什么在一种情况下,我会收到带有字符串文字的已弃用转换警告,而在另一种情况下却没有?
- 在 C++ 中修复类型转换警告的最佳方法
- 为什么仅在列表初始化的情况下才会出现狭窄的转换警告
- -在无符号字符上使用运算符 <<= 时的转换警告
- 如何在gcc或clang中启用从int到int64_t的转换警告
- 如何禁用缩小转换警告
- 使用复合赋值运算符解决转换警告
- gcc 奇怪的转换警告(<B>从"int"转换为"A::count_type {aka short unsigned int}"可能会改变其值)
- 强制缩小转换警告
- 旧风格使用sys/select.h宏强制转换警告