From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <palves@redhat.com>
Cc: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Class-ify ptid_t
Date: Thu, 06 Apr 2017 03:09:00 -0000 [thread overview]
Message-ID: <137a70edf29ba47b7d1d332e18ba3b94@polymtl.ca> (raw)
In-Reply-To: <f9a090d3-69c5-3ad3-0778-db728fcb8af2@redhat.com>
On 2017-04-05 17:31, Pedro Alves wrote:
> - bool is_null () const
> + constexpr bool is_null () const
> {
> return *this == null_ptid;
> }
>
> - bool is_any () const
> + constexpr bool is_any () const
> {
> return *this == minus_one_ptid;
> }
Hmm I think there's a problem with these. null_ptid and minus_one_ptid
are not constant expressions, so these methods (and the ones that use
them) are not really constexpr (you notice when you actually try to use
them as constant expressions). Making null_ptid and minus_one_ptid
constexpr would be useful, I could use them in the static_assert tests
(e.g. to test "matches"). However, when trying to make them constexpr,
it creates a dependency loop: the class needs to be defined after the
null_ptid/minus_one_ptid definitions because it uses them (and you can't
forward declare a constexpr variable I suppose?), but the
null_ptid/minus_one_ptid definitions have to be be defined after the
class, when the type is complete.
An easy workaround would be to not refer to null_ptid/minus_one_ptid in
the class, but use manually crafted values:
constexpr bool is_null () const
{
return *this == ptid_t (0, 0, 0);
}
constexpr bool is_any () const
{
return *this == ptid_t (-1, 0, 0);
}
And to avoid duplication, use defines:
/* Work around the fact that we want to refer to null_ptid and
minus_one_ptid
in the definition of class ptid_t, but they have to be defined after.
*/
#define NULL_PTID ptid (0, 0, 0)
#define MINUS_ONE_PTID ptid (-1, 0, 0)
class ptid_t
{
...
constexpr bool is_null () const
{
return *this == NULL_PTID;
}
constexpr bool is_any () const
{
return *this == MINUS_ONE_PTID;
}
...
}
constexpr ptid_t null_ptid = NULL_PTID;
constexpr ptid_t minus_one_ptid = MINUS_ONE_PTID;
/* We don't want anybody using these macros, they are just temporary.
#undef NULL_PTID
#undef MINUS_ONE_PTID
What do you think?
Now, making null_ptid/minus_one_ptid constexpr brings its share of
fallouts, such as:
/home/simark/src/binutils-gdb/gdb/linux-nat.c: In function âvoid
linux_unstop_all_lwps()â:
/home/simark/src/binutils-gdb/gdb/linux-nat.c:2387:37: error: invalid
conversion from âconst void*â to âvoid*â [-fpermissive]
resume_stopped_resumed_lwps, &minus_one_ptid);
^~~~~~~~~~~~~~~
/home/simark/src/binutils-gdb/gdb/linux-nat.c:980:1: note:
initializing argument 3 of âlwp_info* iterate_over_lwps(ptid_t, int
(*)(lwp_info*, void*), void*)â
iterate_over_lwps (ptid_t filter,
^~~~~~~~~~~~~~~~~
But it looks easy enough to fix by C++-ifying/modernizing
iterate_over_lwps.
next prev parent reply other threads:[~2017-04-06 3:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-04 18:32 [PATCH 1/2] ptid_{lwp,tid}_p: Remove unnecessary checks Simon Marchi
2017-04-04 18:33 ` [PATCH 2/2] Class-ify ptid_t Simon Marchi
2017-04-05 15:47 ` Pedro Alves
2017-04-05 19:44 ` Simon Marchi
2017-04-05 21:31 ` Pedro Alves
2017-04-06 2:15 ` Simon Marchi
2017-04-06 10:49 ` Pedro Alves
2017-04-06 11:12 ` Pedro Alves
2017-04-06 14:32 ` Simon Marchi
2017-04-06 14:38 ` Pedro Alves
2017-04-06 3:09 ` Simon Marchi [this message]
2017-04-06 11:06 ` Pedro Alves
2017-04-05 15:15 ` [PATCH 1/2] ptid_{lwp,tid}_p: Remove unnecessary checks Pedro Alves
2017-04-05 19:21 ` Simon Marchi
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=137a70edf29ba47b7d1d332e18ba3b94@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=simon.marchi@ericsson.com \
/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