https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71913

            Bug ID: 71913
           Summary: [5/6/7 Regression] Missing RVO for operator new
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

void* operator new(unsigned long, void* p) { return p; }
void always_assert(bool);

struct IndirectReturn {
  IndirectReturn() {}
  // Make sure the indirect return value is never copied and RVO kicked in
  IndirectReturn(const IndirectReturn&) { always_assert(false); }
  IndirectReturn& operator=(const IndirectReturn&) = delete;
  ~IndirectReturn() {}
};

IndirectReturn foo();

void bar(void* ptr) {
  IndirectReturn x;

  new (ptr) IndirectReturn(foo());
}
---- CUT -----
In GCC 4.9.3 we did not get the assert but in 5.x and above we do.
This causes HHVM to crash some of the time.
Note if I read C++17 correctly this is a required to get rid of the copy
constructor here.

Reply via email to