June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr Attachments: | On Sun, 07 Jun 2015 18:49:24 +0200, Timon Gehr wrote:
> On 06/06/2015 08:06 AM, ketmar wrote:
>> 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.
>>
>>
> This is valid C:
>
> int main(){
> const auto int x=2;
> return 0;
> }
>
> This is not valid C:
>
> int main(){
> auto auto int x=2; return 0;
> }
>
> What is the problem?
sorry, i didn't realized that this is NG for C language.
| |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr Attachments: | On Sun, 07 Jun 2015 18:50:07 +0200, Timon Gehr wrote:
> On 06/06/2015 08:10 AM, ketmar wrote:
>> if `auto` can play a role of type placeholder
>
> There is no such thing as a type placeholder.
there is:
`immutable auto` -- ok
`immutable const` -- not ok
ergo, `auto` is not a storage class, but type placeholder.
| |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Monday, 8 June 2015 at 07:30:06 UTC, ketmar wrote: > On Sun, 07 Jun 2015 18:50:07 +0200, Timon Gehr wrote: > >> On 06/06/2015 08:10 AM, ketmar wrote: >>> if `auto` can play a role of type placeholder >> >> There is no such thing as a type placeholder. > > there is: > > `immutable auto` -- ok Allocate a variable on the stack, and make it immutable => OK > `immutable const` -- not ok Make the variable immutable, and make it const => nonsense > > ergo, `auto` is not a storage class, but type placeholder. No. | |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz Attachments: | On Mon, 08 Jun 2015 09:27:34 +0000, Marc Schütz wrote:
>> ergo, `auto` is not a storage class, but type placeholder.
>
> No.
and it's not a storage class too. `foreach (auto i; 0..42)` doesn't work, white `foreach (immutable i; 0..42)` works ok.
| |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Monday, 8 June 2015 at 09:33:56 UTC, ketmar wrote:
> On Mon, 08 Jun 2015 09:27:34 +0000, Marc Schütz wrote:
>
>>> ergo, `auto` is not a storage class, but type placeholder.
>>
>> No.
>
> and it's not a storage class too. `foreach (auto i; 0..42)` doesn't work,
> white `foreach (immutable i; 0..42)` works ok.
That's a bug ;-)
| |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | Auto was a storage class in C, but in D it's a type placeholder. | |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Mon, 08 Jun 2015 10:21:25 +0000 Temtaime via Digitalmars-d <digitalmars-d@puremagic.com> wrote: > Auto was a storage class in C, but in D it's a type placeholder. It is still a storage class in D too. http://dlang.org/grammar.html#StorageClasses | |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On 06/08/2015 09:30 AM, ketmar wrote:
> On Sun, 07 Jun 2015 18:50:07 +0200, Timon Gehr wrote:
>
>> On 06/06/2015 08:10 AM, ketmar wrote:
>>> if `auto` can play a role of type placeholder
>>
>> There is no such thing as a type placeholder.
>
> there is:
>
> `immutable auto` -- ok
> `immutable const` -- not ok
>
> ergo, `auto` is not a storage class, but type placeholder.
>
This analogy does not work. 'immutable' and 'automatic storage' do not conflict. 'immutable' and 'const' do conflict.
'immutable auto' is exactly the same as 'auto immutable'. There is no 'int immutable'.
| |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On 06/08/2015 11:33 AM, ketmar wrote: > On Mon, 08 Jun 2015 09:27:34 +0000, Marc Schütz wrote: > >>> ergo, `auto` is not a storage class, but type placeholder. >> >> No. > > and it's not a storage class too. `foreach (auto i; 0..42)` doesn't work, > white `foreach (immutable i; 0..42)` works ok. > foreach(static i;0..42) doesn't work either, and 'static' is a storage class. 'immutable' is a type constructor besides being a storage class. The attributes allowed in `foreach' are those that are considered to make sense, and they are specified in the grammar: http://dlang.org/statement.html#ForeachTypeAttributes Furthermore, both of those declarations are valid: static i = 2; immutable j = 3; What is important is that the type was left out, not that it was replaced by 'auto'. | |||
June 08, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar | On 06/08/2015 09:28 AM, ketmar wrote:
> On Sun, 07 Jun 2015 18:49:24 +0200, Timon Gehr wrote:
>
>> On 06/06/2015 08:06 AM, ketmar wrote:
>>> 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.
>>>
>>>
>> This is valid C:
>>
>> int main(){
>> const auto int x=2;
>> return 0;
>> }
>>
>> This is not valid C:
>>
>> int main(){
>> auto auto int x=2;
>> return 0;
>> }
>>
>> What is the problem?
>
> sorry, i didn't realized that this is NG for C language.
>
This is valid D, but it is pointless:
int main(){
const auto x=2;
return 0;
}
int main(){
auto const x=2;
return 0;
}
This is valid D:
int main(){
const x=2;
return 0;
}
This is not valid D:
int main(){
auto auto x=2;
return 0;
}
int main(){
int const x=2;
return 0;
}
This could be valid D, but isn't (assuming DMD behaves correctly here, I don't think this is documented), because it is pointless, and the compiler is now arbitrarily trying to be helpful:
int main(){
const auto int x=2;
return 0;
}
The error message:
tt.d(2): Error: variable tt.main.x storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?
Note "storage class".
Ditto:
int main(){
auto const int x=2;
return 0;
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply