Opaque type (struct) with a static immutable fails to compile without constructor - why?

frankp frankp_12983 at gmail.com
Thu Mar 4 14:32:04 UTC 2021


On Thursday, 4 March 2021 at 14:18:07 UTC, harakim wrote:
>
>> [...]
>
> This is the text of my program
>
> import std.stdio;
>
> struct Foo_t
> {
>    private long foo;
>    alias foo this;
>    static immutable long Inf = long.max; //1)
>
>    void toString(...){ writeln(foo); }
> }
>
>
> void main()
> {
> 	Foo_t sample;
> 	sample.foo = 100;
> 	
> 	sample.toString();
> }
>
>
> This is the results of running the program:
>
> PS C:\Users\someone\source\tests> dmd forum1.d
> PS C:\Users\someone\source\tests> ./forum1.exe
> 100
> PS C:\Users\someone\source\tests> dmd --version
> DMD32 D Compiler v2.095.1-dirty
> Copyright (C) 1999-2020 by The D Language Foundation, All 
> Rights Reserved written by Walter Bright
>
> So I was not able to reproduce your issue. Is it possible that 
> error is coming from somewhere else?

I wouldn't know, that's why I'm asking here :)
But since it compiles on dmd 2.095.1 I doubt it. I would upgrade 
the compiler but I fear if I do all sorts of other things are 
going to break. I'll keep my workaround and attach a todo note.

Thanks for testing.


More information about the Digitalmars-d-learn mailing list