DIP1000: Walter's proposal to resolve ambiguity of ref-return-scope parameters
Paul Backus
snarwin at gmail.com
Fri Nov 26 02:03:41 UTC 2021
On Friday, 26 November 2021 at 00:31:19 UTC, Dennis wrote:
> On Friday, 26 November 2021 at 00:26:35 UTC, Paul Backus wrote:
>> More seriously: this is exactly the kind of obscure "gotcha"
>> that makes C++ so beginner-hostile, and IMO it is worth going
>> to considerable lengths (including breaking changes) to avoid
>> it.
>
> Allowing breaking changes, what syntax do you think makes
> intuitive sense?
* Allow `return ref` and `return scope`.
* Forbid the `return` storage class from appearing in any other
context.
This means breaking code that uses syntax like `ref return int a`
and `return const ref int b`, which is unambiguous and currently
allowed.
The benefit of this approach is that it establishes an exact,
one-to-one correspondence between syntax and semantics. Rather
than having to apply a bunch of context-dependent rules to work
out which attributes go where, you can just look at the code and
see.
More information about the Digitalmars-d
mailing list