https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109915
Bug ID: 109915
Summary: --suggest-attribute=const misdiagnoses static
functions
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: bruno at clisp dot org
CC: marxin at gcc dot gnu.org
Target Milestone: ---
Created attachment 55126
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55126&action=edit
test case date.c
GCC's --suggest-attribute=const diagnoses static functions, even though the
'const' attribute is useless for static functions (after all, the compiler has
deduced the property on its own). This is leading to my having to litter code
with '__attribute__ (const)' declarations merely to pacify GCC. GCC should
treat the 'const' attribute like other attributes (e.g., malloc, pure), and
should issue the diagnostic only for non-static functions where the attribute
is in fact useful.
How to reproduce:
$ gcc --version
gcc (GCC) 13.1.0
...
$ gcc -ftrapv -Wsuggest-attribute=pure -O2 -S date.c
date.c: In function ‘res_width’:
date.c:5658:12: warning: function might be candidate for attribute ‘const’ if
it is known to return normally [-Wsuggest-attribute=const]
5658 | static int res_width (long int res)
| ^~~~~~~~~