Why can't -O0 fail to disable gcc compilation?

string str="fujian";

Some books say that the code calls the copy constructor, but g ++ optimizes it so that the copy constructor is not called.

However, I used the g ++ -O0 command to disable optimization, but it still cannot call the copy constructor.

How to understand this?

+5
source share
2 answers

With GCC and Clang, you can use the compilation flag -fno-elide-constructorsto disable copy / move optimization optimizations.

+9
source

ISO ++ 12.8. , , "-" 1 ( - "" ), "" , , . , .

undefined, as-if, ( ..). , , .

, elision. , () , .

WG21/N4296

1.9

5 , , . , - undefined, ( , undefined).

8 :

(8.1) - .

(8.2). , , , .

(8.3) - , , . .

. [: . -end note]

12.8

31 , / , , / / . / , .122 /, , ( ):

...

+1

All Articles