Bug in custom test?

Revision en1, by zero4338, 2022-06-28 14:04:14

The code below outputs -8 in cf custom test when using any GNU compiler.
It should output 2 and works well on other online IDEs and my computer.
It also works well on cf when using Clang.
What's the reason for this and how to avoid it?

#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>f;
int mg(pair<int,int>x,pair<int,int>y)
{
	return max(x.second,y.second);
}
int main()
{
	f={{0,-11}};
	for(int J=0;J<=0;J++)
	{
		f[J]=f[0];
		if(J==0)f[J]={0,2};
 		cout<<mg({0,-8},f[J])<<endl;
	}
	return 0;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English zero4338 2022-06-28 14:04:14 585 Initial revision (published)