戻り値の型の暗黙的な型変換が原因である、プログラムのバグを最終的に見つけました。これg++ -Wall
に対する警告はありません。
そんな無知なエラーをいち早く見つけ出す方法はあるのだろうか。
#include <iostream>
// return type should be int, but I wrote bool by mistake
bool foo(int x) {
return x;
}
int main() {
for (int i = 0; i < 100; ++i) {
std::cout << foo(i) << std::endl;
// 0 1 1 1 1 1 ..
// should be 0 1 2 3 4 ...
}
return 0;
}