* [PATCH] c++: Mark member functions as const [PR98951]
@ 2021-02-03 17:31 Marek Polacek
2021-02-03 18:17 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2021-02-03 17:31 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
These member functions look like they could be marked const, since
they don't modify any (non-mutable) class members.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
PR c++/98951
* call.c (struct z_candidate): Mark rewritten and reversed as const.
(struct NonPublicField): Mark operator() as const.
(struct NonTrivialField): Likewise.
---
gcc/cp/call.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 87a7af12796..3068c0f8cfd 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -520,8 +520,8 @@ struct z_candidate {
/* The flags active in add_candidate. */
int flags;
- bool rewritten () { return (flags & LOOKUP_REWRITTEN); }
- bool reversed () { return (flags & LOOKUP_REVERSED); }
+ bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
+ bool reversed () const { return (flags & LOOKUP_REVERSED); }
};
/* Returns true iff T is a null pointer constant in the sense of
@@ -9474,7 +9474,7 @@ first_non_static_field (tree type, Predicate pred)
struct NonPublicField
{
- bool operator() (const_tree t)
+ bool operator() (const_tree t) const
{
return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
}
@@ -9491,7 +9491,7 @@ first_non_public_field (tree type)
struct NonTrivialField
{
- bool operator() (const_tree t)
+ bool operator() (const_tree t) const
{
return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
}
base-commit: 530203d6e3244c25eda4124f0fa5756ca9a5683e
--
2.29.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Mark member functions as const [PR98951]
2021-02-03 17:31 [PATCH] c++: Mark member functions as const [PR98951] Marek Polacek
@ 2021-02-03 18:17 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-02-03 18:17 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 2/3/21 12:31 PM, Marek Polacek wrote:
> These member functions look like they could be marked const, since
> they don't modify any (non-mutable) class members.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK, I guess this is trivial enough for stage4.
> PR c++/98951
> * call.c (struct z_candidate): Mark rewritten and reversed as const.
> (struct NonPublicField): Mark operator() as const.
> (struct NonTrivialField): Likewise.
> ---
> gcc/cp/call.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/cp/call.c b/gcc/cp/call.c
> index 87a7af12796..3068c0f8cfd 100644
> --- a/gcc/cp/call.c
> +++ b/gcc/cp/call.c
> @@ -520,8 +520,8 @@ struct z_candidate {
> /* The flags active in add_candidate. */
> int flags;
>
> - bool rewritten () { return (flags & LOOKUP_REWRITTEN); }
> - bool reversed () { return (flags & LOOKUP_REVERSED); }
> + bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
> + bool reversed () const { return (flags & LOOKUP_REVERSED); }
> };
>
> /* Returns true iff T is a null pointer constant in the sense of
> @@ -9474,7 +9474,7 @@ first_non_static_field (tree type, Predicate pred)
>
> struct NonPublicField
> {
> - bool operator() (const_tree t)
> + bool operator() (const_tree t) const
> {
> return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
> }
> @@ -9491,7 +9491,7 @@ first_non_public_field (tree type)
>
> struct NonTrivialField
> {
> - bool operator() (const_tree t)
> + bool operator() (const_tree t) const
> {
> return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
> }
>
> base-commit: 530203d6e3244c25eda4124f0fa5756ca9a5683e
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-03 18:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 17:31 [PATCH] c++: Mark member functions as const [PR98951] Marek Polacek
2021-02-03 18:17 ` Jason Merrill
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).