Why can't -O0 disable gcc compile optimization?

c++, g++, string

Solution

With GCC and Clang you can use the `-fno-elide-constructors` compilation flag to turn off copy/move elision optimization.

Problem

``` string str="fujian"; ``` Some books say that code will trigger the copy constructor, but g++ will optimize it so that the copy constructor won't be called. However, I used g++ command -O0 to disable the optimization, but it still can't trigger the copy constructor. How to understand it?

Original source