From: Tom Tromey <tom@tromey.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Andrew Burgess <aburgess@redhat.com>,
Tom de Vries <tdevries@suse.de>,
gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb/build] Fix static cast of virtual base
Date: Fri, 08 Mar 2024 09:18:39 -0700 [thread overview]
Message-ID: <87msr8snmo.fsf@tromey.com> (raw)
In-Reply-To: <1e54180b-6665-43c7-9c3c-fdf72bd29a07@polymtl.ca> (Simon Marchi's message of "Wed, 6 Mar 2024 13:27:50 -0500")
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
>> - T result = dynamic_cast<T> (v);
>> - gdb_assert (result != nullptr);
>> + gdb_assert (dynamic_cast<T> (v) != nullptr);
>> +
>> + /* If a base class of V is virtual then the dynamic_cast will succeed,
>> + but the production mode static_cast will fail. So having checked with
>> + the dynamic_cast that we didn't get nullptr, now use static_cast to
>> + catch the virtual base case. This has the side effect of guaranteeing
>> + that GDB will compile in production mode. */
>> + T result = static_cast<T> (v);
>> #else
>> T result = static_cast<T> (v);
>> #endif
>>
Simon> This is similar to what I proposed here:
Simon> https://inbox.sourceware.org/gdb-patches/24af4ea8-5426-4ce4-b1c5-12858b38a952@simark.ca/
Simon> The idea is the same, to have a static_cast in the DEVELOPMENT branch.
Simon> I kinda like my version better, as it factors out the static cast
Simon> (notice that both branches have identical static_cast lines after your
Simon> patch) and the ifdef is just around a single assert. Also, I'm pretty
Simon> sure the nullptr check is not necessary, as both dynamic_cast and
Simon> static_cast can handle it.
I think either of these would be fine.
Tom
next prev parent reply other threads:[~2024-03-08 16:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 16:18 Tom de Vries
2024-02-23 13:56 ` Tom Tromey
2024-03-06 17:39 ` Andrew Burgess
2024-03-06 18:27 ` Simon Marchi
2024-03-08 16:18 ` Tom Tromey [this message]
2024-03-11 10:25 ` Andrew Burgess
2024-03-11 16:22 ` Simon Marchi
2024-03-19 14:58 ` Andrew Burgess
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=87msr8snmo.fsf@tromey.com \
--to=tom@tromey.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
--cc=tdevries@suse.de \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).