This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug web/79738] New: Documentation for __attribute__((const)) slightly misleading
- From: "m-gccbugs at bodyfour dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 27 Feb 2017 21:40:06 +0000
- Subject: [Bug web/79738] New: Documentation for __attribute__((const)) slightly misleading
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79738
Bug ID: 79738
Summary: Documentation for __attribute__((const)) slightly
misleading
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: web
Assignee: unassigned at gcc dot gnu.org
Reporter: m-gccbugs at bodyfour dot uk
Target Milestone: ---
Looking at the description of __attribute__((const)) at:
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
"Basically this is just slightly more strict class than the pure attribute
below, since function is not allowed to read global memory."
That's almost correct -- it's not allowed to read memory that can change. You
could argue that "global" implies the .data space, but to a lay programmer it
would suggest you can't do any memory reads except on your own stack.
To take a trivial example, it's fine for this to be ((const)):
static const int TABLE[] = { 1, 2, 3 };
extern int lookup(unsigned x) __attribute__((const));
int lookup(unsigned x)
{
return TABLE[x];
}
...and if fact, -Wsuggest-attribute=const will warn if you don't have the
attribute there.
I suggest amending the documentation to say "...is not allowed to read from any
memory location whose contents can change between calls"