On 04/02/2018 12:09 AM, Sandra Loosemore wrote:
On 03/27/2018 03:21 PM, Pedro Alves wrote:
On 03/27/2018 09:19 PM, Martin Sebor wrote:
On 03/27/2018 01:38 PM, Pedro Alves wrote:
On 03/27/2018 07:18 PM, Martin Sebor wrote:
+Because a @code{pure} function can have no side-effects it does not
FWIW, I'd suggest rephrasing as:
Because a @code{pure} function cannot have side effects
because "can have no side-effects" can be read as
"is allowed to have no side effects", which gave me pause
when I read it the first time, and is the opposite of
what you mean.
That is what I meant: that const and pure functions are not allowed
to have any side-effects. If they did, they could be unexpectedly
eliminated (i.e., the behavior is undefined when such a function
does have a side-effect).
I know, but that's not what I read the first time (and found it
odd so I had to re-read). You can either assume that I'm the
only one that will misunderstand it on first read, or you can
swap a couple words and be sure no one will misunderstand it.
Up to you.
I'm chiming in a little late here, but I agree with Pedro that "can have
no side-effects" is confusing. I'd say "cannot have side effects" or
"must have no side effects" instead.
There's nothing confusing about it. It's an established phrase
with millions of uses and only one meaning. According to Google
Books Ngram Viewer it's also more pervasive than either of
the two suggested alternatives:
http://goo.gl/FgXgwi
Also note that non-hyphenated "side effects" seems to be preferred usage
as a noun phrase (at least it's the only form listed by m-w.com).
I'm all for using the preferred form. I've made the change here
and submitted a separate patch to remove the hyphen from the rest
of the occurrences.
Attached is a changed patch that uses "cannot have side effects"
instead of "can have no side effects."
Martin
gcc/ChangeLog:
* doc/extend.texi (Common Function Attributes): Clarify.
(const attribute): Likewise.
(pure attribute): Likewise.
Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi (revision 259017)
+++ gcc/doc/extend.texi (working copy)
@@ -2275,8 +2275,11 @@ on a declaration, followed by an attribute specifi
parentheses. You can specify multiple attributes in a declaration by
separating them by commas within the double parentheses or by
immediately following an attribute declaration with another attribute
-declaration. @xref{Attribute Syntax}, for the exact rules on
-attribute syntax and placement.
+declaration. @xref{Attribute Syntax}, for the exact rules on attribute
+syntax and placement. Compatible attribute specifications on distinct
+declarations of the same function are merged. An attribute specification
+that is not compatible with attributes already applied to a declaration
+of the same function is ignored with a warning.
GCC also supports attributes on
variable declarations (@pxref{Variable Attributes}),
@@ -2499,7 +2502,7 @@ themselves to optimization such as common subexpre
The @code{const} attribute imposes greater restrictions on a function's
definition than the similar @code{pure} attribute below because it prohibits
the function from reading global variables. Consequently, the presence of
-the attribute on a function declarations allows GCC to emit more efficient
+the attribute on a function declaration allows GCC to emit more efficient
code for some calls to the function. Decorating the same function with
both the @code{const} and the @code{pure} attribute is diagnosed.
@@ -2507,8 +2510,9 @@ both the @code{const} and the @code{pure} attribut
Note that a function that has pointer arguments and examines the data
pointed to must @emph{not} be declared @code{const}. Likewise, a
function that calls a non-@code{const} function usually must not be
-@code{const}. It does not make sense for a @code{const} function to
-return @code{void}.
+@code{const}. Because a @code{const} function cannot have any side
+effects it does not make sense for such a function to return @code{void}.
+Declaring such functions is diagnosed.
@item constructor
@itemx destructor
@@ -3218,6 +3222,9 @@ The @code{pure} attribute imposes similar but loos
a function's defintion than the @code{const} attribute: it allows the
function to read global variables. Decorating the same function with
both the @code{pure} and the @code{const} attribute is diagnosed.
+Because a @code{pure} function cannot have any side effects it does not
+make sense for such a function to return @code{void}. Declaring such
+functions is diagnosed.
@item returns_nonnull
@cindex @code{returns_nonnull} function attribute