1. 11
  1.  

  2. 11

    For reference:

    Copy elision [is the only allowed form of optimization (until C++14)][one of the two allowed forms of optimization, alongside allocation elision and extension, (since C++14)] that can change the observable side-effects. Because some compilers do not perform copy elision in every situation where it is allowed (e.g., in debug mode), programs that rely on the side-effects of copy/move constructors and destructors are not portable.

    https://en.cppreference.com/w/cpp/language/copy_elision

    1. 2

      In other words, constructors and destructors are not necessarily good ideas, and should be utilized sparingly.

      It’s a shame there are so many footguns in CPP.

      1. 2

        Well, they’re OK as long as they’re pure, i.e. don’t have observable effects, which is good practice anyway.