【发布时间】:2017-05-06 16:04:34
【问题描述】:
看那个例子:
//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;
}
与:
$ g++ -Wall -Wextra -Wpedantic test.cpp:
4294967295 -1
4294967295 -1
为什么 gcc 会放过这个?是否有检测这种隐式转换的选项?
干杯
【问题讨论】:
-
@Rakete1111
unsigned int通常与int具有相同的宽度。
标签: c++ g++ implicit-conversion