D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11440 - struct initialization with partially initialized data crashes
Summary: struct initialization with partially initialized data crashes
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-04 11:22 UTC by Daniel Davidson
Modified: 2024-12-13 18:13 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Daniel Davidson 2013-11-04 11:22:54 UTC
import std.stdio;

struct Y {
  private immutable(int)[] _data;
}

struct CFS {
  double x = 5;
  Y growth;
}

void main() {
  auto s = CFS(1.0);      // crash
  //auto s = CFS(1, Y()); // crash
  //auto s = CFS(1, Y([])); // works
  writeln(s);
}

If x is an int there is no problem.
If s is not accessed there is no problem, so it dies in the writeln call.
Comment 1 Martin Krejcirik 2013-11-04 13:11:15 UTC
Can't reproduce both on Linux and Windows x86.
Comment 2 burg.basile 2013-11-04 15:09:34 UTC
import std.stdio;

struct Y {
  private
	immutable(int)[] _data;
	immutable(int)[] _data2;
}

struct CFS {
  double x = 5;
  Y growth;
}

void main() {
  auto s = CFS(1.0);
  writeln(s);
}

runs.

It seems to be more related to the the "private" token.
Comment 3 burg.basile 2013-11-04 15:29:24 UTC
(In reply to comment #2)
> import std.stdio;
> 
> struct Y {
>   private:
>     immutable(int)[] _data;
>     immutable(int)[] _data2;
> }
> 
> struct CFS {
>   double x = 5;
>   Y growth;
> }
> 
> void main() {
>   auto s = CFS(1.0);
>   writeln(s);
> }
> 
> runs.
> 
> It seems to be more related to the the "private" token.
EDIT:
BTW either with private: or private{*/two or more declarations/*}
Comment 4 Kenji Hara 2013-11-04 18:32:33 UTC
http://forum.dlang.org/post/nlyjuddqfpdkwfkalxax@forum.dlang.org

> > It doesn't happen with -O, or when compiled with LDC or GDC.
> 
> And it doesn't happen when building with -m32 (I'm on x86_64
> linux).
Comment 5 dlangBugzillaToGithub 2024-12-13 18:13:40 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18708

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB