Given this code
#include <iostream>
#include <initializer_list>
#include <string>
int a, b;
int main() {
for (auto p : std::initializer_list<std::pair<int &, std::string>>{
{ a, "a" },
{ b, "b" },
})
{
std::cout << p.second << ": " << p.first << '\n';
}
}
I expect the output
a: 0
b: 0
and gcc and clang agree, however, Visual Studio 2013 Update 5 (my version, not sure what rextester uses) disagrees and prints this:
: 0
: 0
Visual Studio had an issue with std::initializer_list
, but it is supposed have been fixed since update 2.
Is this a bug in Visual Studio or am I invoking undefined or unspecified behavior?