May 18, 2010
Don wrote:
> bearophile wrote:
>> Steven Schveighoffer:
>>> No, I was simply wrong :)  I think it's by design.  Which means the  original bug report is valid.
>>
>> The original bug report is valid, but I don't understand that code still. Is the const implying a static only in some situations?
>>
>> Why is this OK for the compiler:
>>
>> struct Foo {
>>     const Foo f = Foo();
>> }
>> static assert(Foo.sizeof == 1);
>> void main() {}
>>
>>
>> While this is not OK for the compiler?
>>
>> struct Foo {
>>     const Foo f;
>> }
>> static assert(Foo.sizeof == 1);
>> void main() {}
>>
>> Bye,
>> bearophile
> 
> In D1, the two are totally different. The second one is the only situation in D1 where 'const' doesn't mean compile-time constant.
> I guess the same behaviour has been applied in D2, but I'm not sure if that's intentional or not.

D'oh, should read the title. This was a D1 question. Yes it's intentional, and yes it's confusing.
May 18, 2010
Don:
> D'oh, should read the title. This was a D1 question. Yes it's intentional, and yes it's confusing.

Sorry, I have added more confusion.
I have added this, but I have used DMD2:
http://d.puremagic.com/issues/show_bug.cgi?id=4203

Bye,
bearophile
May 29, 2010
strtr wrote:
> Should I report these bugs?

The general answer to this question is: Yes, as long as
* you're sure it's a bug
* you can reproduce it in a current version of DMD or GDC
* it isn't already reported

The bug reporting system is here:
http://d.puremagic.com/issues/

> (and how should I call this first one?)
<snip>
> --
> main.d(4): Error: struct main.S no size yet for forward reference
> main.d(4): Error: struct main.S no size yet for forward reference
> main.d(11): Error: cannot evaluate opCall() at compile time
> ----

Puzzling.  It appears that line 2 is somehow helping the compiler to get it right - and without it, the compiler gets thrown while trying to make sense of the S() you're setting S2 to.  But the line numbers you're getting are puzzling in any case.

In any case, there's certainly a bug here.

<snip>
> --
> run main.exe
> Error: ArrayBoundsError main.d(8)
> should be t_def.d(8)
> ----

That's certainly a bug that needs to be reported if it isn't reported already.

> ----
> module main;
> 
> const S S1 = S();
> 
> struct S
> {
>   static S func( S s_ )
>   out(result){ assert(false,random); }
>   body{ return s_; }
> 
>   const S S2 = func(S());
> }
> void main(){}
> --
> main.d(8): Error: __error <---# should be assert failure #

The error should be "undefined identifier random".

> main.d(11): Error: cannot evaluate func((S())) at compile time

Indeed, this is probably a bug along the same lines as the compiler's tendency to treat invalid expressions as being subsequently of type int.

Stewart.
May 29, 2010
Steven Schveighoffer wrote:
<snip>
> Unlike some languages, D1 const does not imply static.  Which means you are trying to define an S as containing an S, which would then contain another S and so on.  This should work:

It's implying static in this context according to my testing.  Try this at home:

----------
import std.stdio;

const S S1 = S();
struct S {
    float value;
    static S opCall() {
        S s;
        s.value = 42;
        return s;
    }
    const S S2 = S();
}
pragma(msg, S.sizeof);
pragma(msg, S1.value);
pragma(msg, S.S2.value);
----------
1 2
Next ›   Last »