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

            Bug ID: 117127
           Summary: Feature request: Warning on useless 'const' in a
                    function declaration
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rdiez-2006 at rd10 dot de
  Target Milestone: ---

Sometimes, I forget to remove useless 'const' modifiers in function
declarations  in header files when copying the function prototype from the .cpp
file. A simplified example is:

file.h:

// Non-defining function declaration ("prototype" in C terminology).
int f ( const int a );  // 'const' is useless here.


file.cpp:

// Function definition.
int f ( const int a )  // 'const' does make sense here.
{
   return a;
}

I would like GCC to issue warnings for such useless 'const' modifiers in
function declarations (not definitions). At the very least, it would save some
head scratching during code reviews.

Apparently, clang-tidy has option 'readability-avoid-const-params-in-decls' for
such a warning:

https://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-const-params-in-decls.html

There was a recent discussion about this in the mailing list:
Warning on useless 'const' in a function declaration
Mon Oct 7 14:24:38 GMT 2024
https://gcc.gnu.org/pipermail/gcc-help/2024-October/143768.html

Reply via email to