From some feedback I received on some of the attribute warnings
new in GCC 8 it seems that the manual could stand to be clarified
to explain why it makes no sense for a function declared with
attribute const (and pure) to return void.  The attached patch
adds a bit more text to make it clear.

In addition, I took the opportunity to clarify how attributes
on multiple declarations of the same function are treated.

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 258899)
+++ 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 can have no 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 can have no 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

Reply via email to