www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug in gdc or bug in dmd?

reply David Rushby <David_member pathlink.com> writes:
Here's the example program:
-------------------------------------------------
const int *x;
int y = 1;

int main() {
printf("*x is %d\n", *x);
return 0;
}

static this() {
x = &y;
}
-------------------------------------------------
dmd 0.136 compiles this without an error message, and of course the output is
"*x is 1".

The most recent version of gdc (0.15) issues this output when I try to compile
the example program:
-------------------------------------------------
const_lvalue.d:10: x is not an lvalue
const_lvalue.d:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
-------------------------------------------------

Obviously gdc's internal compiler error is a bug in any case, but should it be
possible to initialize 'const' variables in a module's static constructor?
Oct 24 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David Rushby schrieb am 2005-10-25:
 Here's the example program:
 -------------------------------------------------
 const int *x;
 int y = 1;

 int main() {
 printf("*x is %d\n", *x);
 return 0;
 }

 static this() {
 x = &y;
 }
 -------------------------------------------------
 dmd 0.136 compiles this without an error message, and of course the output is
 "*x is 1".

 The most recent version of gdc (0.15) issues this output when I try to compile
 the example program:
 -------------------------------------------------
 const_lvalue.d:10: x is not an lvalue
 const_lvalue.d:0: internal compiler error: Segmentation fault
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 -------------------------------------------------

 Obviously gdc's internal compiler error is a bug in any case, but should it be
 possible to initialize 'const' variables in a module's static constructor?
- -> http://digitalmars.com/d/attribute.html Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDYYlR3w+/yD4P9tIRAvLOAJ4yeLUX2zmOGrFe2aaJ5g+m/FrdZQCguycU qjFmtWw6NlbAlcIiJNGp8fU= =evwV -----END PGP SIGNATURE-----
Oct 28 2005
parent David Rushby <David_member pathlink.com> writes:
In article <h3e833-a76.ln1 eiche.kuehne.cn>, Thomas Kuehne says...
David Rushby schrieb am 2005-10-25:
 Here's the example program:
 ...
- -> http://digitalmars.com/d/attribute.html
Thanks, Thomas. Somehow I missed the second part of the 'const' documentation when I looked at it previously.
Oct 28 2005