Possible enhancement: Concise return statements
Jonathan M Davis
jmdavisProg at gmx.com
Mon Aug 15 14:00:58 PDT 2011
On Monday, August 15, 2011 13:31 Walter Bright wrote:
> On 8/15/2011 1:13 PM, Steven Schveighoffer wrote:
> > On Mon, 15 Aug 2011 16:05:31 -0400, Walter Bright
> > <newshound2 at digitalmars.com>
> >
> > wrote:
> >> On 8/15/2011 12:17 PM, Steven Schveighoffer wrote:
> >>> What is going to happen if someone adds an extra ';' ? Compiler error
> >>> ("no return statement")
> >>
> >> Such lambdas are often used with 'auto' returns, so you'd get no
> >> compiler error, but a subtle in the way your program works.
> >
> > So you're saying it becomes a void function? This still is not bad:
> >
> > 1. Caller is expecting it not to be void, compiler error
> > 2. Caller is not using the return value, who cares?
>
> With struct destructors, (2) is a problem. Overloading can also be a
> problem.
It would be a big problem with regard to functions in general IMHO, but how do
struct destructors and overloading apply to lambdas? It at least _seems_ like
it would be possible to make it so that single-statement lambdas which have no
return or ; but return the result of that statement would work without any
ambiguities.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list