[PATCH] D25124: Support rvalue references in enumerate range adapter.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 13:33:09 PDT 2016


zturner created this revision.
zturner added reviewers: chandlerc, dblaikie.
zturner added subscribers: llvm-commits, dblaikie.

@dblaikie  pointed an issue wherein if you wrote a ranged-based for like this:

  for (auto X : enumerate(std::vector<int>{1,2,3})) {
  }

The vector would be destroyed since the range adapter stored the argument by reference.  This patch adds a new template to stl extras called `remove_rvalue_reference` which is similar to `std::remove_reference` but only removes rvalue reference.  This way, if it is constructed with an rvalue, it will copy the range, but if it is constructed with an lvalue, it will store by reference.

A test is added to verify that it works.  The same test was confirmed to segfault before this patch.


https://reviews.llvm.org/D25124

Files:
  include/llvm/ADT/STLExtras.h
  unittests/ADT/STLExtrasTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25124.73128.patch
Type: text/x-patch
Size: 4063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160930/b4a6d544/attachment.bin>


More information about the llvm-commits mailing list