[doc,committed] clarify docs for function attribute "const"
Sandra Loosemore
sandra@codesourcery.com
Fri Dec 14 02:33:00 GMT 2018
On 12/13/18 3:52 PM, Martin Sebor wrote:
> Ping: https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00426.html
>
> (I have now committed the @code{const} cleanup mentioned below.)
This patch is OK except for one nit.
> @cindex pointer arguments
> 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}. 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 a function is diagnosed.
> +pointed to must @emph{not} be declared @code{const} if the pointed-to
> +data might change between successive invocations of the function. In
> +general, since a function cannot distinguish data that might change
> +from data that cannot, const functions should never be
> +pass-by-reference (take pointer or, in C++, reference arguments).
I'd really rather avoid "pass-by-reference" since it adds nothing with
the clarification about what it means there, too. How about just:
...const functions should never take pointer or, in C++, reference
arguments.
OK to commit with that fixed.
-Sandra
More information about the Gcc-patches
mailing list