On Thu, 12 Jul 2018 at 11:41, Richard Sandiford wrote:
> +Only use non-constant references in the following situations:
> +</p>
> +
> +<ul>
> +<li>when they are necessary to conform to a standard interface, such as
> +the first argument to a non-member <code>operator+=</code></li>

And the return value of such operators (which also applies to member
operators, which is the more conventional way to write compound
assignment operators).

> +<li>in a return value, when providing access to something that is known
> +to be nonnull</li>
> +</ul>
> +
> +<p>
> +In other situations the convention is to use pointers instead.
> +</p>
> +
> +<blockquote>
> +<pre><code>HOST_WIDE_INT do_arith (..., bool *overflow);   // OK
> +HOST_WIDE_INT do_arith (..., bool &amp;overflow);   // Please avoid

I understand the objection to using references for out parameters (an
alternative to pointers is to return a struct with the wide int result
and the overflow flag), but ...

> +int *elt = &amp;array[i];  // OK
> +int &amp;elt = array[i];   // Please avoid

... this seems unnecessary. If the function is so long that the fact
elt is a reference can easily get lost, the problem is the length of
the function, not the use of a reference.

Reply via email to