In the popular gcc compiler, and more specifically, in its optimizer, another error was detected leading to a Runtime error during program execution. When the O2 compiler option is enabled, the optimizer incorrectly processes a certain program template, which leads to fatal consequences.
Bug posted our compatriot Maxim Ivanov (
http://e-maxx.ru ), by the way, departing a month later at the ACM World Programming Championship. :)
The minimized test code looks like this:
for (int i=0; i<=1; i++)
for (int j=0; j<=1; j++) {
std::vector a[2];
a[i].push_back (0);
}
The error manifests itself if we put the local array of vectors into a double nested loop — the first attempt to write to the vector will result in a Runtime. At the same time, optimization is normal when at least one of the following conditions is met:
a) The size of the array of vectors is larger than the loop walks
b) Refer to the vector not by a [i], but through a [0], or a [1], or any other constant value
c) Before writing to a vector, execute a = std :: vector ();
It should be noted that this code is correctly compiled in Visual Studio of any version.
The error was fixed by Richard Guenther and the fix is uploaded today in the
gcc repository .
')
Be careful when writing programs for nuclear power plants and nuclear warheads using gcc :)
Bug report .