c++ - Weird GCC array initialization behavior -



c++ - Weird GCC array initialization behavior -

i encountered variant of code when looking @ question (the original code used std::thread instead of std::vector, syntax same):

#include <iostream> #include <vector> #include <iterator> #include <algorithm> int main() { std::vector<double> vecs[10] = std::vector<double>(10, 1); for(auto& vec: vecs){ std::copy(vec.begin(), vec.end(), std::ostream_iterator<double>(std::cout, " ")); std::cout<<std::endl; } homecoming 0; }

this code shouldn't compile; std::vector<double> vecs[10] = std::vector<double>(10, 1); not valid initialization syntax, , clang rejects error: array initializer must initializer list. however, gcc accepts it , appears initialize every vector in list re-create of specified temporary.

is gcc extension i've never heard (that somehow managed survive -pedantic-errors) or plain bug?

i consider bug.

#include <vector> int main() { std::vector<double> x = std::vector<double>(10, 1); std::vector<double> vecs[10] = x; homecoming 0; }

works (as have spotted).

while

int main() { int x = 10; int is[10] = x; homecoming 0; }

yields (expected) error.

c++ gcc

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -