https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108380
Bug ID: 108380 Summary: function execution order Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sameer.varyani at gmail dot com Target Milestone: --- #include <iostream> #include <string> #include <map> #include <vector> int values(){ std::cout << "calling values" << std::endl; static int idx; return idx++; } std::string keys(){ std::cout << "calling keys" << std::endl; static std::vector<std::string> str = {"A", "B", "C", "D", "E"}; static int a; return str[(a++)%str.size()]; } int main(int argc, char **argv){ std::map<std::string, int> mm; mm[keys()] = values(); } g++ -std=c++17 test.cpp ; ./a.out calling values calling keys g++ -std=c++14 test.cpp ; ./a.out calling keys calling values clang is consistent across standards. clang++ -std=c++17 test.cpp ; ./a.out calling values calling keys Also not that the if the values return type is changes to std::string the order in c++17 and c++14 stay consistent.