[Issue 10980] static initialization of immutable structs with disabled postblit fails
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 8 23:34:38 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10980
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |pull, rejects-valid
Summary|[reg] static initialization |static initialization of
|of immutable structs with |immutable structs with
|disabled postblit fails |disabled postblit fails
Severity|regression |blocker
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2013-09-08 23:34:36 PDT ---
(In reply to comment #0)
> Let S be a struct a disabled potsblit, and we want to create a static instance
> of an immutable S:
>
> //----
> alias immutable(S) IS;
> static IS i = IS.init;
> //----
>
> 2.060: OK!
> 2.061: Error: variablei of type struct immutable(S) uses this(this), which is
> not allowed in static initialization
> 2.062: Error: variable hello.i of type struct immutable(S) uses this(this),
> which is not allowed in static initialization
> 2.063: OK!
> 2.063.2: OK!
>
> So... it broke and it was fixed (apparently).
The issue had not been fixed, instead it just be hidden by the regression bug
10998, from 2.063.
> BUT!
> Let's try that in a template now:
>
> //----
> template foo(T)
> {
> static T i = T.init;
> alias i foo;
> }
>
> struct S
> {
> @disable this(this);
> }
> alias immutable(S) IS;
>
> //IS i = IS.init; //Uncoment me
>
> void main()
> {
> auto p = &foo!IS;
> }
> //----
> 2.060: OK!
> 2.061: Error: variable main.i of type struct immutable(S) uses this(this),
> which is not allowed in static initialization
> 2.062: Error: variable main.i of type struct immutable(S) uses this(this),
> which is not allowed in static initialization
> 2.063: Error: template instance main.foo!(immutable(S)) error instantiating
> 2.063.2: Error: template instance main.foo!(immutable(S)) error instantiating
>
> Now, we simply have an "unclear" error that the template failed, but with no
> diagnostics (at least, I am unable to provide any).
>
> Funny story: if we uncomment the global static, it works again. Another
> workaround is to declare the static inside a function, and have the function
> return the static by reference.
>
> This issue is also "semi-blocker" in emplace, which needs to create a static
> instance of T, no matter T's type.
Because the current compile-time postblit call check is not enough strict. I
opened a compiler fix to improve check mechanism.
https://github.com/D-Programming-Language/dmd/pull/2541
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list