Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

GNU G++ bug with global set

Revision en1, by Dardy, 2019-06-03 05:07:35

Me and MrOkasha found an odd quirk with the GNU G++ compiler, (we tested with G++11, G++14, and G++17, all having the same bug).

This code here:


#include <bits/stdc++.h>
using namespace std;

set<double> st;

int main() {

    double x, y;
    for(int i = 0; i < 3; ++i){
        cin >> x >> y;
        st.insert(y/x);
    }
    cout << st.size() << endl;
}
// input:    5 -2 5 -2 5 -2

should output without any doubt '1', as the set should remove duplicate numbers. The output is 3 for some reason on the GNU compilers. It should be noted that the output is indeed 1 on Clang++17 compiler, Visual C++, and other available versions of GNU G++ compilers found online, for us, it seems the bug only occurs here on codeforces, verified by the Custom Invocation feature.

The weirdest thing about this bug is that, for some bizarre reason, if the declaration of the set set<double> is moved to inside the main function, the code works as intended.

Any thoughts on this weird issue?

Tags gnu c++, bug report, c++ compilers, set

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Dardy 2019-06-03 05:07:35 1146 Initial revision (published)