This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/81518] New: missing warning on a violation of attribute const requirements


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

            Bug ID: 81518
           Summary: missing warning on a violation of attribute const
                    requirements
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The description of the const attribute in the GCC manual contains this note:

    Note that a function that has pointer arguments and examines the data
pointed to must not be declared const. Likewise, a function that calls a
non-const function usually must not be const. It does not make sense for a
const function to return void.

Despite the note GCC doesn't issue a warning for function declarations that
violate these requirements.  To help avoid user mistakes it would be helpful to
add such a warning.

$ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic a.c

void f (void*) __attribute__ ((const));

$

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]