[LLVMbugs] [Bug 16993] New: Assign rvalue to self

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Aug 25 01:36:50 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16993

            Bug ID: 16993
           Summary: Assign rvalue to self
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: ruslan_baratov at yahoo.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I've found out that some libc++ STL containers works incorrect while
assigning rvalue to self. For example std::vector:

#include <iostream> // std::cout
#include <vector>

int main() {
  std::vector<int> a(1000);
  std::cout << a.capacity() << std::endl; // 1000
  a = std::move(a);
  std::cout << a.capacity() << std::endl; // 0
  a[100] = 0x0; // Segmentation fault
  return EXIT_SUCCESS;
}

And, I think, is right.

>From standard 17.6.4.9 Function arguments [res.on.arguments]:

— If a function argument binds to an rvalue reference parameter, the
implementation may assume that this parameter is a unique reference to this
argument. [ Note: If the parameter is a generic parameter of the form T&& and
an lvalue of type A is bound, the argument binds to an lvalue reference
(14.8.2.1) and thus is not covered by the previous sentence. —end note ] [
Note: If a program casts an lvalue to an xvalue while passing that lvalue to a
library function (e.g. by calling the function with the argument move(x)), the
program is effectively asking that function to treat that lvalue as a
temporary. The implementation is free to optimize away aliasing checks which
might be needed if the argument was an lvalue. —end note ]

1. Am I quoting standard correctly?
2. Is it refer to STL containers only ("evil" optimization) or general C++11
rule (good practice?)
3. Can you provide an assert(_LIBCPP_ASSERT?) in debug mode to check violation
of this rule?

PS MSVC check (this != &ref) and works correcty, libstdc++ not check and
segfaulting too.

-- 
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/20130825/083cb85a/attachment.html>


More information about the llvm-bugs mailing list