June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Friday, 5 June 2015 at 17:50:55 UTC, ketmar wrote:
> `const int` works, so i can't see why `auto auto` is failing.
Wrong analogy. Try `const const`, and it will fail with the same error as `auto auto`: "redundant attribute".
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Meta | On 6/5/15 12:19 PM, Meta wrote:
> On Friday, 5 June 2015 at 12:32:03 UTC, ketmar wrote:
>> but it does! both with 2.067.1 downloaded from dlang.org and with git
>> HEAD. it may not do what you expect it to do (i don't know what it should
>> do anyway), but dmd happily accepts that code.
>
> Hmm, maybe I'm only on 2.070 then. I'll upgrade and see if it still
> fails to compile.
Hello from the future!!!
When I use auto int a in a normal function, I get this:
Error: auto can only be used for template function parameters
But unaryFun()(auto int a) is a template. Perhaps your blocker is for non-templates?
-Steve
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Friday, 5 June 2015 at 18:35:51 UTC, Marc Schütz wrote:
> On Friday, 5 June 2015 at 17:50:55 UTC, ketmar wrote:
>> `const int` works, so i can't see why `auto auto` is failing.
>
> Wrong analogy. Try `const const`, and it will fail with the same error as `auto auto`: "redundant attribute".
const auto ans = 42;
compiles fine for me, so auto clearly can be used as a type.
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 5 June 2015 at 19:38:06 UTC, Steven Schveighoffer wrote:
> On 6/5/15 12:19 PM, Meta wrote:
>> On Friday, 5 June 2015 at 12:32:03 UTC, ketmar wrote:
>>> but it does! both with 2.067.1 downloaded from dlang.org and with git
>>> HEAD. it may not do what you expect it to do (i don't know what it should
>>> do anyway), but dmd happily accepts that code.
>>
>> Hmm, maybe I'm only on 2.070 then. I'll upgrade and see if it still
>> fails to compile.
>
> Hello from the future!!!
>
> When I use auto int a in a normal function, I get this:
>
> Error: auto can only be used for template function parameters
>
> But unaryFun()(auto int a) is a template. Perhaps your blocker is for non-templates?
>
> -Steve
Yes, this is a non-template function that is auto-generated.
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to krzaq | On Friday, 5 June 2015 at 19:45:18 UTC, krzaq wrote:
> const auto ans = 42;
>
> compiles fine for me, so auto clearly can be used as a type.
So does "auto immutable" or "auto pure" or "pure a".
They're all storage classes and any storage class can kick off a declaration:
@nogc a = 10; // compiles!
dmd is just not really consistent on when it issues errors on redundant, conflicting, or useless storage classes.
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Friday, 5 June 2015 at 03:15:46 UTC, anonymous wrote: > On Friday, 5 June 2015 at 02:38:39 UTC, ketmar wrote: >> here's dustmited source: > > Further reduced: > > void unaryFun()(auto int a) pure nothrow @safe @nogc {} > alias Identity(F) = F; > void main() > { > unaryFun!()(41); > static void fun(int n) pure nothrow @safe @nogc {} > alias F = typeof(fun); > pragma(msg, F); /* ...(int n) */ > pragma(msg, Identity!F); /* ...(auto int) */ > } Filed two issues: https://issues.dlang.org/show_bug.cgi?id=14656 https://issues.dlang.org/show_bug.cgi?id=14657 | |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Friday, 5 June 2015 at 10:56:36 UTC, ketmar wrote:
>
> p.s. if "auto" is a storage class, the following code should be accepted
> (while it isn't):
>
> int foo () { return 42; }
>
> void main () {
> auto auto i = foo();
> }
>
> as it's logically "an auto-typed var with "auto" storage class".
Here lies your mistake. There is no such thing as "auto"-typed (leaving aside function signatures, which might be special-cased and are different beast altogether). Auto is not a type. auto* or auto[] aren't valied either. Auto is just a storage class, no more, no less. You use it if the grammar needs a storage class but you don't want to give special attributes to the variable (like const or static). To make a declaration with inferred type you need at least one storage class. To make it work with "normal" variables you use "auto".
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On 06/05/2015 02:33 PM, ketmar wrote:
> i agree, i think it was a keyword used 'cause it was already used in C.
> but it's meaning is completely redefined in D.
The meaning is exactly the same. It's the default storage class.
| |||
June 06, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz Attachments: | On Fri, 05 Jun 2015 18:35:49 +0000, Marc Schütz wrote:
> On Friday, 5 June 2015 at 17:50:55 UTC, ketmar wrote:
>> `const int` works, so i can't see why `auto auto` is failing.
>
> Wrong analogy. Try `const const`, and it will fail with the same error as `auto auto`: "redundant attribute".
nope. in `auto auto` one `auto` is storage type, and another `auto` is a type placeholder. see, `const auto` works, so `auto` can play role of a type placeholder. so `auto auto` should be accepted, if you insists that it can play a role of storage class.
| |||
June 06, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr Attachments: | On Sat, 06 Jun 2015 00:28:51 +0200, Timon Gehr wrote:
> On 06/05/2015 02:33 PM, ketmar wrote:
>> i agree, i think it was a keyword used 'cause it was already used in C. but it's meaning is completely redefined in D.
>
> The meaning is exactly the same. It's the default storage class.
then i'll fill a bug about `auto auto` and will reopen it until it's fixed.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply