This is the mail archive of the
mailing list for the GDB project.
Re: [RFA 02/22] Use RAII to save and restore scalars
- From: Tom Tromey <tom at tromey dot com>
- To: Tom Tromey <tom at tromey dot com>
- Cc: Pedro Alves <palves at redhat dot com>, Trevor Saunders <tbsaunde at tbsaunde dot org>, gdb-patches at sourceware dot org
- Date: Fri, 30 Sep 2016 22:23:20 -0600
- Subject: Re: [RFA 02/22] Use RAII to save and restore scalars
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com> <firstname.lastname@example.org> <20160927085937.com7c7ct4wuchzpg@ball> <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
Pedro> Guess we could have the copy constructor actually move instead of
Pedro> copy, setting the copied-from's pointer member to NULL, and then
Pedro> have the destructor do nothing if the pointer is NULL.
Tom> Yeah. I took this approach. I'm not super thrilled with it, but at the
Tom> same time it's not *too* bad.
Scratch that, I spoke too soon. I couldn't get this to work.
I don't understand why the 2-argument form of make_scoped_restore
requires a copy constructor while the 1-argument form does not.
However, once you need a copy constructor, it doesn't seem possible
without a move constructor. The issue is that a copy constructor take a
const reference, so you can't modify the fields of the original.
Removing the 2-argument form seems to work. Though like I said, I don't
Also, as an aside, I found I was using nullptr in my patches, but this
isn't C++03. I think -std=c++03 is going to be needed or else it will
be too easy to slip in C++11-isms. Now, I do think C++11 is really much
better, but my understanding is that C++03 is what gdb decided on.