auto limitation?

Maxim Fomin maxim at maxim-fomin.ru
Tue Sep 11 12:21:55 PDT 2012


On Tuesday, 11 September 2012 at 19:07:52 UTC, Simen Kjaeraas 
wrote:
> On Tue, 11 Sep 2012 20:57:07 +0200, Maxim Fomin 
> <maxim at maxim-fomin.ru> wrote:
>
>> I think it is UB rather than a bug. The spec says that return 
>> types must match exactly. AFAIK auto is a feature to infer 
>> return type, not to magically adjust to multiple incompatible 
>> types.
>
> I'd be surprised if this were not a bug. My expectation would 
> be that the
> types be combined as with the ?: operator, just like 
> std.traits.CommonType.
>
> If this is not a bug, it's certainly worth filing as an 
> enhancement request.

It can do, but in compile time. At runtime it cannot know what 
type is returned (I suppose, but I am not expert in such things). 
Variant works because it does it in compile time, but buggy 
examples published so far do it at runtime.


More information about the Digitalmars-d-learn mailing list