This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch]New feature to all kind of stl container.vector::data_move() returns vector::data() that can be moved,just as unique_ptr::release() to unique_ptr::get()
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Anthony Shipman <als at iinet dot net dot au>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 8 Jan 2015 15:52:42 +0000
- Subject: Re: [Patch]New feature to all kind of stl container.vector::data_move() returns vector::data() that can be moved,just as unique_ptr::release() to unique_ptr::get()
- Authentication-results: sourceware.org; auth=none
- References: <tencent_1737FA275BA843B20700F485 at qq dot com> <tencent_215CF4C848ACCCEF53C7F318 at qq dot com> <CAH6eHdSY1_YDN1DMRCjnFRFLsn2Ju9ScJD7VoYJFpfEkwiurTw at mail dot gmail dot com> <201501090219 dot 30548 dot als at iinet dot net dot au>
On 8 January 2015 at 15:19, Anthony Shipman wrote:
> On Fri, 9 Jan 2015 12:36:05 am Jonathan Wakely wrote:
>> That is a poor interface, which can cause currently working code to leak
>> memory.
>>
>> extern "C" void some_function(const int*, size_t);
>> std::vector<int> get_values(size_t n);
>> ...
>> some_function(get_values(5).data(), 5);
>>
>> Today this works correctly. With your suggestion the call to data()
>> would release ownership of the memory and it would never be freed.
>>
> Why would this happen? Is there some sort of implied operator=(&&) for
> the int* type?
I don't understand the question. Why would what happen?