This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

debug vector move issue


Hi

While working on debug forward_list I noticed that all debug containers were missing move constructor and move assignment operator from normal container. I started adding those and will submit a patch for that however there is a problem on vector. Attached is a test I wrote for this container.

When compiled with the necessary attached patch on debug vector it works fine. However when you define _GLIBCXX_DEBUG_PEDANTIC the test a.capacity() == r.capacity() fails. This is because when you create a normal vector by moving a debug one internal memory is transferred but the debug vector _M_guaranteed_capacity is not reseted. This result in the test by the moved debug vector instance 'a' announcing a capacity of 1 when in fact it is 0.

I see no real good solution to this problem, _M_guarantied_capacity seemed to be impossible to maintain when the debug container is moved. Maybe putting this data in the allocator could help, I need to investigate.

Any thoughts ?

Francois

Attachment: vector.patch
Description: Text document

// { dg-options "-std=gnu++0x" }

// Copyright (C) 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

#define _GLIBCXX_DEBUG_PEDANTIC

#include <debug/vector>
#include <utility>
#include <testsuite_hooks.h>

void test01()
{
  bool test __attribute__((unused)) = true;

  // Move between debug vectors:
  __gnu_debug::vector<int> a;
  a.push_back(1);
  int* int_ptr = &a.front();
  __gnu_debug::vector<int> b(std::move(a));
  VERIFY( b.size() == 1 && b[0] == 1 && &b.front() == int_ptr );

  a = std::move(b);
  VERIFY( a.size() == 1 && a[0] == 1 && &a.front() == int_ptr );

  // Move from debug vector to normal one:
  std::vector<int> c(std::move(a));
  VERIFY( c.size() == 1 && c[0] == 1 && &c.front() == int_ptr );
  const std::vector<int>& r(a);
  VERIFY( a.capacity() == r.capacity() );

  a.push_back(1);
  int_ptr = &a.front();
  c = std::move(a);
  VERIFY( c.size() == 1 && c[0] == 1 && &c.front() == int_ptr );

  // Move from normal vector to debug one:
  a = std::move(c);
  VERIFY( a.size() == 1 && a[0] == 1 && &a.front() == int_ptr );
  VERIFY( a.capacity() >= a.size() );

  c.push_back(1);
  int_ptr = &c.front();

  __gnu_debug::vector<int> d(std::move(c));
  VERIFY( d.size() == 1 && d[0] == 1 && &d.front() == int_ptr );
  VERIFY( d.capacity() >= d.size() );
}

int main(void)
{
  test01();
  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]