www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd segfaults

reply "matovitch" <camille.brugel laposte.net> writes:
Hi !

Does anybody knows why dmd segfaults on this code ? Should I 
report this as a bug ?

import std.stdio;

enum LiftingGender
{
     PREDICT,
     UPDATE,
}

struct Test(float[][] coeffs,
             int[] offsets,
             LiftingGender gender)
{
     immutable float[][] coeffs = coeffs;
     immutable int[] offsets = offsets;
     immutable LiftingGender gender;
}

void main()
{
     Test!([[0.5,-1]], [-1], LiftingGender.PREDICT) test;

     writeln(test);
}
May 31 2014
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
matovitch:

 Does anybody knows why dmd segfaults on this code ? Should I 
 report this as a bug ?
Please report this minimized case to Bugzilla: struct Foo(int[] arr) { const int[] arr = arr; } void main() { Foo!([0]) foo; } The error it gives before the crash: test.d(2,17): Deprecation: variable test.Foo!([0]).Foo.arr const field with initializer should be static, __gshared, or an enum The cause of the crash if that the local variable has the same name as the template argument, combined with the reported error. Bye, bearophile
May 31 2014
parent reply "matovitch" <camille.brugel laposte.net> writes:
On Saturday, 31 May 2014 at 17:01:23 UTC, bearophile wrote:
 matovitch:

 Does anybody knows why dmd segfaults on this code ? Should I 
 report this as a bug ?
Please report this minimized case to Bugzilla: struct Foo(int[] arr) { const int[] arr = arr; } void main() { Foo!([0]) foo; } The error it gives before the crash: test.d(2,17): Deprecation: variable test.Foo!([0]).Foo.arr const field with initializer should be static, __gshared, or an enum The cause of the crash if that the local variable has the same name as the template argument, combined with the reported error. Bye, bearophile
Thanks ! I should have minimized it. Anyway I discovered I had already a bugzilla account unfortunately I can't remember my password and the email takes his time... :-(
May 31 2014
parent reply "matovitch" <camille.brugel laposte.net> writes:
In fact it segfauls on any template parameter if it has the same 
name as the immutable member (at least it's coherent). Something 
as simple as :

struct Foo(int i)
{
     immutable int i = i;
}

void main()
{
     Foo!5 foo;
     writeln(foo);
}

I am suprised that nobody tried this before. BTW I am starting to 
worry : my mail didn't arrived yet. I would be very grateful if 
someone could report this for me. :S
May 31 2014
next sibling parent "matovitch" <camille.brugel laposte.net> writes:
I remembered my psswd don't take my last sentence into account (i 
will filed this).
May 31 2014
prev sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Saturday, 31 May 2014 at 17:22:41 UTC, matovitch wrote:
 In fact it segfauls on any template parameter if it has the 
 same name as the immutable member (at least it's coherent). 
 Something as simple as :

 struct Foo(int i)
 {
     immutable int i = i;
 }

 void main()
 {
     Foo!5 foo;
     writeln(foo);
 }

 I am suprised that nobody tried this before. BTW I am starting 
 to worry : my mail didn't arrived yet. I would be very grateful 
 if someone could report this for me. :S
It doesn't even need a template, this crashes too: struct Test { immutable float[] i = i; }
May 31 2014
parent "matovitch" <camille.brugel laposte.net> writes:
I updated the issue. Strangely if done in the main everything is 
fine :

Error: undefined identifier i
May 31 2014
prev sibling parent "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
On Sat, May 31, 2014 at 04:50:11PM +0000, matovitch via Digitalmars-d-learn
wrote:
 Hi !
 
 Does anybody knows why dmd segfaults on this code ? Should I report
 this as a bug ?
[...] Compiler segfaults should always be reported. No matter how wrong the code may be, it is never right for the compiler to crash -- it should reject the code and terminate normally. T -- Never ascribe to malice that which is adequately explained by incompetence. -- Napoleon Bonaparte
May 31 2014