GCC 5.4 compiles this without any warnings (using -std=c++11 -Wall -pedantic):
#include <iostream>
struct Coord {
double x, y;
};
Coord origin() {
return {0.0, 0.0};
}
int main() {
Coord c = origin();
std::cout << "(" << c.x << ", " << c.y << ")\n";
}
It looks like {0.0, 0.0} creates an std::initializer_list that gets used to construct to a Coord, even though I haven't defined such a constructor.
Do structs have implicit conversion constructors for an std::initializer_list? If so, what are the rules for when this constructor is generated and how it works? If not, why does this compile without warning?