This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [patch] proposed fix for libstdc++/59829


On 27/01/14 23:37 +0000, Jonathan Wakely wrote:
On 27 January 2014 20:35, Jonathan Wakely wrote:
On 27 January 2014 20:12, Marc Glisse wrote:
On Mon, 27 Jan 2014, Jonathan Wakely wrote:

This is the best I've come up with to avoid dereferencing an invalid
pointer when calling vector::data() on an empty vector.

For C++03 we reurn the vector's pointer type, so can just return the
internal pointer, but for C++11 we need to convert that to a raw
pointer, which we do by dereferencing, so we must check if it's valid
first.


For comparison, libc++ has 2 paths. If pointer really is a pointer, it just
returns it, no need to pay for a comparison in that case. And otherwise, it
calls _M_start.operator-> and crosses its fingers. There is a helper
function doing that used throughout the library.

Ah yes, I remember Howard posting a get_raw_pointer() function to the
reflector that used operator->() on user-defined types ... I don't
really like calling that on a potentially invalid pointer though. The
user-defined pointer type in my new testcase could just as easily
throw if operator-> is called on an invalid pointer.  As Paolo also
mentioned avoiding the branch for built-in pointers I'll do that.

Here's what I'm committing, the testcase is simplified by reusing the
new PointerBase type I added to testsuite_allocator.h

Tested x86_64-linux, committed to trunk.

Attachment: patch-2.txt
Description: Text document


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