Consider the following C++11 code:
#include <initializer_list>
struct MyStruct {
MyStruct() {}
MyStruct(const MyStruct& other) {}
void doStuff() const {}
};
int main() {
MyStruct a;
auto b{a};
a.doStuff();
b.doStuff();
return 0;
}
I was expecting b
to be an instance of MyStruct
, copy-constructed from a
, but instead, b
is an std::initializer<MyStruct>
when compiled with GCC 4.9.1. GCC 8.2 compiles this as expected.
NOTE I made an example of this on Godbolt: https://godbolt.org/z/adNDoO
Could you please explain the difference between the two compiler versions? (Or what the standard states for that matter?)