[llvm-bugs] [Bug 46519] New: Copy elision is not performed for objects with non overlapping lifetimes

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 30 08:01:14 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46519

            Bug ID: 46519
           Summary: Copy elision is not performed for objects with non
                    overlapping lifetimes
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider the example:


struct widget {
  widget();
  widget(widget&&);
};

// Inspired by https://wg21.link/p2025
widget test(int i) {
  {
      widget w1;
      if (i == 1) return w1;
  }
  widget w2;
  return w2;
}


Lifetimes of w1 and w2 do not overlap and it is possible to elide the move
constructor by constructing w1 and w2 at the same destination address.

Godbolt playground: https://godbolt.org/z/BZPgwi

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200630/6b8ac0d5/attachment.html>


More information about the llvm-bugs mailing list