diff mbox

Improve insert/emplace robustness to self insertion

Message ID 20160712140424.GA12493@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely July 12, 2016, 2:04 p.m. UTC
On 08/07/16 17:38 +0100, Jonathan Wakely wrote:
>On 06/07/16 21:46 +0200, François Dumont wrote:
>>Don't you plan to add it to the testsuite ?
>
>Done with the attached aptch.

Just for completeness, I'm also adding the example from LWG 2164,
which is related.

Tested x86_64, committed to trunk.
diff mbox

Patch

commit 23cb1117d3b5073097ab15fcf9c0245aa98de067
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Tue Jul 12 14:00:11 2016 +0000

    Add std::vector::emplace() testcase from LWG 2164
    
    	* testsuite/23_containers/vector/modifiers/emplace/self_emplace.cc:
    	Add testcase from LWG 2164.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238243 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/self_emplace.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/self_emplace.cc
index d452b5b..8712216 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/self_emplace.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/self_emplace.cc
@@ -135,6 +135,20 @@  test04()
   VERIFY( va[0]._i == 1 );
 }
 
+void
+test05()
+{
+  // LWG DR 2164
+  std::vector<int> v;
+  v.reserve(4);
+  v = { 1, 2, 3 };
+  v.emplace(v.begin(), v.back());
+  VERIFY( v[0] == 3 );
+  VERIFY( v[1] == 1 );
+  VERIFY( v[2] == 2 );
+  VERIFY( v[3] == 3 );
+}
+
 int main()
 {
   test01();