From: Aurelian Melinte <ame01@gmx.net>
To: gdb@sourceware.org
Subject: Re: SIGSERV termination on return statement
Date: Thu, 11 Oct 2012 00:27:00 -0000 [thread overview]
Message-ID: <5076125E.3060207@gmx.net> (raw)
In-Reply-To: <1349884852.11402.YahooMailRC@web181302.mail.ne1.yahoo.com>
On 10/10/2012 12:00 PM, Arthur Schwarz wrote:
> The object is deleted and not used within this context. The error occurs before
> the assignment is complete.
>
> I might have a (very strong) misunderstanding of how C++ references work, but,
> I don't think that gdb should just quit and not allow me to debug.
>
>
> In SlipSublist::replace if 'SlipCell& cell' is changed to 'SlipCell* cell',
> with appropriate changes to the remaining code, then no error occurs. It is
> only when a reference is used do I get into difficulty. I get a SIGSERV error
> from gdb in this context and in others when an assignment is made to a
> reference variable, 'cell' in this case. Whenever 'variable = somereference' is
> executed, gdb faults. 'somereference' can be a function or a variable.
>
> The questions I have are (1) can reference variables not be reassigned?, and (2)
> is gdb's SIGSERV fault a legitimate fault or a bug?
>
> Thanks for taking the time;
> art
>
Well... A C++ reference has different semantics than a Java reference
(and my Java is rusty). Under the hood (I mean what the compiler uses
when dealing with a reference) a reference is a pointer. But at the
surface where the programmer is, a reference will not allow you certain
types of operations permitted on pointers, in particular, you can only
initialize a reference; but you cannot re-assign it. I do not have the
patience to get through the standardese but check this:
http://en.wikipedia.org/wiki/Reference_%28C%2B%2B%29: "Once a reference
is created, it cannot be later made to reference another object; it
cannot be /reseated/. This is often done with pointers."
Which is why this code makes me think of a compiler bug and I suspect
that assignment is simply dropped and cell still points to the deleted
*this:
SlipCell& cell = *this; // Ref initialization
cell = assignData(X); // Ref re-assignment verboten. Compiler should have croaked.
You can check with the debugger where that cell ref points before and
after the re-assignment in the delete case but before returning from
replace().
Regards,
Aurelian
>
>
> ----- Original Message ----
> From: Aurelian Melinte<ame01@gmx.net>
> To: Arthur Schwarz<aschwarz1309@att.net>
> Cc:gdb@sourceware.org
> Sent: Tue, October 9, 2012 4:32:20 PM
> Subject: Re: SIGSERV termination on return statement
>
> On 09/10/2012 5:48 PM, Arthur Schwarz wrote:
>
>> SlipCell& SlipSublist::replace(SlipCell& X) { // Replace a
>> cell
>> on a list with a new cell
>> SlipCell& cell = *this;
>> if (X.isData()) {
>> cell = assignData(X); // failure before return to this statement
>>
> from
>
>> method
>> *** delete this;
>> } else {
>> *this = X;
>> }
>> *** return cell;
>> }; // SlipCell& SlipSublist::replace(SlipCell& X)
>>
>>
> Are you returning from a deleted object then using it afterward?
>
> Regards,
> Aurelian
>
>
next prev parent reply other threads:[~2012-10-11 0:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 21:48 Arthur Schwarz
2012-10-09 23:32 ` Aurelian Melinte
2012-10-10 16:01 ` Arthur Schwarz
2012-10-11 0:27 ` Aurelian Melinte [this message]
2012-10-11 9:40 ` John Gilmore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5076125E.3060207@gmx.net \
--to=ame01@gmx.net \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox