Consider this sample of code:
#include <initializer_list>
#include <iostream>
int main()
{
for(auto e: []()->std::initializer_list<int>{return{1,2,3};}())
std::cout<<e<<std::endl;
return 0;
}
I tried to compile it with g++ (gcc version 4.9.2 (Debian 4.9.2-10)) and the output is correct. In clang++ (Debian clang version 3.5.0-9 (tags/RELEASE_350/final) (based on LLVM 3.5.0)) output for example:
0
2125673120
32546
Where first line are always 0 and last two are "random".
It's error in clang or something else? I think that this sample of code is correct.
Update:
When the lambda function return type is something else (e.g. std::vector or std::array) this code works fine.
Aucun commentaire:
Enregistrer un commentaire