On 11/26/18 8:32 PM, Martin Sebor wrote:
On 11/26/18 11:13 AM, Sandra Loosemore wrote:
On 11/26/18 10:17 AM, Martin Sebor wrote:
On 11/25/18 6:40 PM, Sandra Loosemore wrote:
I've checked in the attached patch for PR79738.
I think we have lost something important with the clarification
of attribute const:
The @code{const} attribute imposes greater restrictions on
a function's definition than the similar @code{pure} attribute
below because it additionally prohibits the function from reading
memory except for constant global variables.
Permitting a const function to only read global constants means
it can't read local variables (including static const locals).
Something like the following should fix that:
The @code{const} attribute prohibits a function from accessing
objects whose value can change between successive invocations of
the function. Functions declared with the @code{const} attribute
may access non-volatile constant objects with any storage duration.
The attribute imposes greater restrictions on a function's definition
than the similar @code{pure} attribute.
I have also removed the mention of global variables (since objects
at other scopes, including static locals or thread-local variables,
are also included) and instead of "reading" used the term "accessing"
since const functions can neither read nor write such objects.
Finally, I've avoided describing the attribute in terms of pure
("additionally") and instead only mentioned pure for reference.
Let me know how this sounds.
Hmmm. If we go with this wording, then the description of "pure"
needs to be updated too, since it also uses the "constant global
variables" language now to describe how it differs from "pure". I
think we do need some succinct summary of exactly how the two
attributes differ to explain why it is an error to provide both
attributes and help users choose which is more appropriate. Using
parallel language except in the particulars that differ is one way to
accomplish that.
I admit I really struggled with the wording in coming up with the
previous patch.... :-( I thought I understood the difference, but I
guess not. :-(
I agree that both const and pure should be updated as well. Let
me put together a patch for both.
Thanks. I was going to take another stab at it myself after finishing
some other stuff in my queue, but I'll wait and see what you suggest.
-Sandra