Why this code yield different result in C++14 and C++17?

Revision en1, by WeZoomIn, 2019-10-02 16:47:18

I'm using Codeforces custom test. When compile and run, this code yield different results,

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

int k;
map<int,int> a[2];
int bar () {
	return ++k;
}
void foo () {
	a[k][1] = bar();

}
int main() {
	k=0;
	foo ();
	cout<<a[0][1]<<" "<<a[1][1]<<endl;
	return 0;
}

//GNU G++11, GNU G++14 yield "1 0"
//GNU G++17 yield "0 1"

Is there any issue about this? What is expected behavior is this case?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English WeZoomIn 2019-10-02 16:47:18 536 Initial revision (published)