#include <ios>
#include <iostream>
#include <map>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
map<int, int> v;
int i;
int t;
while (cin >> i) {
v[i] = t++;
}
auto mi = i;
auto mt = t;
for (const auto p : v) {
if (p.second < mt) {
mi = p.first;
mt = p.second;
}
}
cout << mi << '\n';
return 0;
}
The above program makes heavy use of an uninitialized variable t
, but GCC does not report this using -Wall or -Wuninitialized. Why is this so?
It is worth noting that Klang catches him:
main.cpp:13:12: warning: variable 't' is uninitialized when used here [-Wuninitialized]
v[i] = t++;
^
Used by g ++ (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2).
Clang version 4.0.1 is used (tags / RELEASE_401 / final).
As you can see at https://godbolt.org/g/kmYMC1 GCC 7.2 does not report this even if necessary. I will create a ticket in the GCC problem controller.
source
share