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.

Reply via email to