public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98951] New: gcc/cp/call.c: 4 * member functions can be marked const
@ 2021-02-03 12:31 dcb314 at hotmail dot com
  2021-02-03 15:39 ` [Bug c++/98951] " mpolacek at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-03 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98951

            Bug ID: 98951
           Summary: gcc/cp/call.c: 4 * member functions can be marked
                    const
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

$ fgrep /cp/call.c cppcheck.20210202.out  | fgrep functionConst
trunk.git/gcc/cp/call.c:523:8: style:inconclusive: Technically the member
function 'z_candidate::rewritten' can be const. [functionConst]
trunk.git/gcc/cp/call.c:524:8: style:inconclusive: Technically the member
function 'z_candidate::reversed' can be const. [functionConst]
trunk.git/gcc/cp/call.c:9477:8: style:inconclusive: Technically the member
function '::NonPublicField::operator()' can be const. [functionConst]
trunk.git/gcc/cp/call.c:9494:8: style:inconclusive: Technically the member
function '::NonTrivialField::operator()' can be const. [functionConst]
$

I tried the obvious diff:

$ git diff gcc/cp/call.c 
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 87a7af12796..0467c2ef3eb 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);
   }

and it seems to build ok.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98951] gcc/cp/call.c: 4 * member functions can be marked const
  2021-02-03 12:31 [Bug c++/98951] New: gcc/cp/call.c: 4 * member functions can be marked const dcb314 at hotmail dot com
@ 2021-02-03 15:39 ` mpolacek at gcc dot gnu.org
  2021-02-03 18:25 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-03 15:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98951

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-02-03

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looks like a good idea.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98951] gcc/cp/call.c: 4 * member functions can be marked const
  2021-02-03 12:31 [Bug c++/98951] New: gcc/cp/call.c: 4 * member functions can be marked const dcb314 at hotmail dot com
  2021-02-03 15:39 ` [Bug c++/98951] " mpolacek at gcc dot gnu.org
@ 2021-02-03 18:25 ` cvs-commit at gcc dot gnu.org
  2021-02-03 18:25 ` mpolacek at gcc dot gnu.org
  2021-02-03 18:48 ` dcb314 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-03 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98951

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:b52a1dfe12a6303c7649f3ff5b8dac6c1001d49a

commit r11-7090-gb52a1dfe12a6303c7649f3ff5b8dac6c1001d49a
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Feb 3 11:58:13 2021 -0500

    c++: Mark member functions as const [PR98951]

    These member functions look like they could be marked const, since
    they don't modify any (non-mutable) class members.

            PR c++/98951
            * call.c (struct z_candidate): Mark rewritten and reversed as
const.
            (struct NonPublicField): Mark operator() as const.
            (struct NonTrivialField): Likewise.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98951] gcc/cp/call.c: 4 * member functions can be marked const
  2021-02-03 12:31 [Bug c++/98951] New: gcc/cp/call.c: 4 * member functions can be marked const dcb314 at hotmail dot com
  2021-02-03 15:39 ` [Bug c++/98951] " mpolacek at gcc dot gnu.org
  2021-02-03 18:25 ` cvs-commit at gcc dot gnu.org
@ 2021-02-03 18:25 ` mpolacek at gcc dot gnu.org
  2021-02-03 18:48 ` dcb314 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-03 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98951

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98951] gcc/cp/call.c: 4 * member functions can be marked const
  2021-02-03 12:31 [Bug c++/98951] New: gcc/cp/call.c: 4 * member functions can be marked const dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2021-02-03 18:25 ` mpolacek at gcc dot gnu.org
@ 2021-02-03 18:48 ` dcb314 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-03 18:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98951

--- Comment #4 from David Binderman <dcb314 at hotmail dot com> ---
Thanks for the fast fix. 

Since this bug has gone so well, you may like to have a look at # 97894.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-03 18:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 12:31 [Bug c++/98951] New: gcc/cp/call.c: 4 * member functions can be marked const dcb314 at hotmail dot com
2021-02-03 15:39 ` [Bug c++/98951] " mpolacek at gcc dot gnu.org
2021-02-03 18:25 ` cvs-commit at gcc dot gnu.org
2021-02-03 18:25 ` mpolacek at gcc dot gnu.org
2021-02-03 18:48 ` dcb314 at hotmail dot com

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).