On 5 May 2012 00:04, Amit Markel wrote:
> Hello, please consider the little program below which was compiled on GCC 
> 4.7.0.

Your question is inappropriate on this list which is for discussing
development of GCC not with GCC.  Your question would be appropriate
on the gcc-help list, please take any follow up there, thanks.

> /*              auto */ vector<int> arr = {i,i+1,i+2};

With 'auto' here the type is not vector<int>, it's
std::initializer_list<int>, which is a lightweight utility type that
refers to a temporary array. An initializer_list is intended to be
used only as a temporary or other short-lived type.

In your code the initializer_list gets copied into the std::thread,
but then the temporary array it uses goes out of scope. When the add()
function runs a std::vector is constructed from the initializer_list,
copying the data from the invalid array that has already gone out of
scope.

Reply via email to