| Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 05, 2015 Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
This is so completely bizarre that I thought I was going crazy at first, but the same behaviour is exhibited whether I'm using my own copy of std.functional or a copy cloned straight from phobos master. The following code snippet exhibits different behaviour when it is put in a standalone file than when it is in std.functional:
unittest
{
struct Foo2
{
int fun(int n) pure nothrow @safe @nogc
{
return n;
}
}
import std.traits;
pragma(msg, ParameterTypeTuple!(typeof(Foo2.fun)));
}
If I put the following snippet in test.d and run `dmd -unittest -main test.d`, it prints `(int)`.
HOWEVER, if I append the snippet to the end of std.functional and run
`dmd -unittest -main std\functional.d`, it prints `(auto int)` instead.
Can anyone else duplicate this bug at the very least? What in the world could be causing this?
| ||||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Meta | I reproduced this bug on my arch linux with DMD 2.067 and git phobos (4cea8f1e4dd839568cc9e581bc15ee84f02e7135) | |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Meta | here's dustmited source:
template unaryFun(alias fun, string parmName="a") {
static if (is(typeof(fun)))
auto unaryFun(ElementType) (auto ElementType __a) {
mixin("alias " ~ parmName ~ " = __a ;");
return mixin(fun);
} else static if (needOpCallAlias) {
unaryFun fun;
}
}
unittest {
cast(void)unaryFun!"a+1"(41); // silence warning
}
unittest {
struct Foo2 {
int fun (int n) pure nothrow @safe @nogc { return n; }
}
import std.traits;
pragma(msg, ParameterTypeTuple!(typeof(Foo2.fun)));
}
# dmd -c -o- -unittest test.d to see `(auto int)`
note that after removing any attribute from `Foo2.foo` will emit correct `(int)`.
| |||
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 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) */
}
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to anonymous Attachments: | On Fri, 05 Jun 2015 03:15:45 +0000, 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) */
> }
`auto int a`?! it shouldn't be accepted at all!
O_O
| |||
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 03:45:18 UTC, ketmar wrote:
> `auto int a`?! it shouldn't be accepted at all!
Yeah, but it's the same with "auto ref".
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to anonymous Attachments: | On Fri, 05 Jun 2015 03:56:05 +0000, anonymous wrote:
> On Friday, 5 June 2015 at 03:45:18 UTC, ketmar wrote:
>> `auto int a`?! it shouldn't be accepted at all!
>
> Yeah, but it's the same with "auto ref".
`auto ref` has a well-defined meaning. yet `auto int` is nonsence. it's definitely a compiler bug. ;-)
| |||
June 05, 2015 Re: Code behaves incorrectly if it is compiled in std.functional | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ketmar Attachments: | On Fri, 05 Jun 2015 04:39:28 +0000, ketmar wrote:
> On Fri, 05 Jun 2015 03:56:05 +0000, anonymous wrote:
>
>> On Friday, 5 June 2015 at 03:45:18 UTC, ketmar wrote:
>>> `auto int a`?! it shouldn't be accepted at all!
>>
>> Yeah, but it's the same with "auto ref".
>
> `auto ref` has a well-defined meaning. yet `auto int` is nonsence. it's definitely a compiler bug. ;-)
i mean "there are at least two different things in that code, and they triggers two different compiler bugs".
| |||
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 04:39:28 UTC, ketmar wrote:
> On Fri, 05 Jun 2015 03:56:05 +0000, anonymous wrote:
>
>> On Friday, 5 June 2015 at 03:45:18 UTC, ketmar wrote:
>>> `auto int a`?! it shouldn't be accepted at all!
>>
>> Yeah, but it's the same with "auto ref".
>
> `auto ref` has a well-defined meaning. yet `auto int` is nonsence. it's
> definitely a compiler bug. ;-)
I don't think so. `auto` is a valid storage class like `const`, `immutable` and `shared`.
| |||
June 05, 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 09:44:09 +0000, Marc Schütz wrote:
> On Friday, 5 June 2015 at 04:39:28 UTC, ketmar wrote:
>> On Fri, 05 Jun 2015 03:56:05 +0000, anonymous wrote:
>>
>>> On Friday, 5 June 2015 at 03:45:18 UTC, ketmar wrote:
>>>> `auto int a`?! it shouldn't be accepted at all!
>>>
>>> Yeah, but it's the same with "auto ref".
>>
>> `auto ref` has a well-defined meaning. yet `auto int` is nonsence. it's definitely a compiler bug. ;-)
>
> I don't think so. `auto` is a valid storage class like `const`, `immutable` and `shared`.
`auto` is not a storage class, but a `type placeholder`. at least this is what i've been told by W or A (sorry, i can't remember the link; i think it was somewhere in NG... or in bugzilla...). there is one exception to this rule, though: `auto ref`.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply