Inconsistent behavior of compiler optimization of unused string
I am curious why the following piece of code: #include <string> int main() { std::string a = "ABCDEFGHIJKLMNO"; } when compiled with -O3 yields the following code: main: # @main xor eax, eax ret (I perfectly understand that there is no need for the unused a so the compiler can entirely omit it from the generated code) However the following program: #include <string> int main() { std::string a = "ABCDEFGHIJKLMNOP"; // <-- !!! One Extra P } yields: main: # @main push rbx sub rsp, 48 lea rbx, [rsp + 32] mov qword ptr [rsp + 16], rbx mov qword ptr [rsp + 8], 16 lea rdi, [rsp + 16] lea rsi, [rsp +