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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to