https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106135

            Bug ID: 106135
           Summary: Found a bug in gcc
           Product: gcc
           Version: 10.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 85811545 at qq dot com
  Target Milestone: ---

This code will output wrong result when execute g++ code.cpp -o code -lm -O2
-DONLINE_JUDGE -std=c++11 using g++10.3.0, on Ubuntu 20.04,64bits. 


#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;
}


The correct result is 2 (don't use -O2 or add ''cout<<"" ' in code) but it
output -8 (using -O2)

Reply via email to