[PATCH] D47067: Update NRVO logic to support early return

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 30 12:54:09 PDT 2018


rsmith added a comment.

Slightly reduced testcase:

  template<typename T> T f(T u, bool b) {
    T t;
    if (b) return t;
    return u;
  }
  struct X { X(); X(const X&); ~X(); void *data; };
  
  template X f(X, bool);

... which compiles to:

  X f(X u, bool b) {
    X::X(&return-slot);
    if (b) return;
    X::X(&return-slot, u);
    X::~X(&return-slot);
  }

... due to `t` incorrectly being used as an NRVO variable.


Repository:
  rC Clang

https://reviews.llvm.org/D47067





More information about the cfe-commits mailing list