I played with Godbolt CompilerExplorer. I wanted to see how good certain optimizations are. My minimal working example:
#include <vector> int foo() { std::vector<int> v {1, 2, 3, 4, 5}; return v[4]; }
Generated assembler (by clang 5.0.0, -O2 -std = C ++ 14):
foo():
Apparently, clang knows the answer, but before returning a lot of material. It seems to me that even the vector was created due to the "new / delete operator".
Can someone explain to me what is going on here and why he didn’t just come back?
The code generated by GCC (not copied here) seems to explicitly create a vector. Does anyone know that GCC is not able to output the result?
c ++ compiler-optimization gcc clang
Max Görner Nov 02 '17 at 9:53 on 2017-11-02 09:53
source share