Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 12, 2004 dmd 101: crash | ||||
---|---|---|---|---|
| ||||
class A {
const int b;
this()
{
b = 2;
}
}
void main()
{
A a = new A();
a.b = 5; //remove this line, no crash
}
D:\D\src\temp>dmd const.d
const.d(5): b is not an lvalue
<crash>
Regan
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
|
September 13, 2004 Re: dmd 101: crash | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Regan Heath wrote:
> class A {
> const int b;
> this()
> {
> b = 2;
> }
> }
>
> void main()
> {
> A a = new A();
> a.b = 5; //remove this line, no crash
> }
>
> D:\D\src\temp>dmd const.d
> const.d(5): b is not an lvalue
> <crash>
>
> Regan
>
Isn't this intended behavior? A const must be defined not declared (ie., It's value must be know upon first encounter). And once known, such value cannot be overridden.
Andrew
|
September 13, 2004 Re: dmd 101: crash | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tyro | On Sun, 12 Sep 2004 21:37:56 -0400, Tyro <ridimz_at@yahoo.dot.com> wrote: > Regan Heath wrote: > >> class A { >> const int b; >> this() >> { >> b = 2; >> } >> } >> >> void main() >> { >> A a = new A(); >> a.b = 5; //remove this line, no crash >> } >> >> D:\D\src\temp>dmd const.d >> const.d(5): b is not an lvalue >> <crash> >> >> Regan >> > Isn't this intended behavior? A const must be defined not declared (ie., It's value must be know upon first encounter). And once known, such value cannot be overridden. Yes, the error is correct, line 5 is "b = 2;" in the ctor for the class. However, the compiler crashes when it sees the "a.b = 5;" line, that is the bug. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
September 13, 2004 Re: dmd 101: crash | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | > Yes, the error is correct, line 5 is "b = 2;" in the ctor for the class. However, the compiler crashes when it sees the "a.b = 5;" line, that is the bug.
>
> Regan
>
I C. Thanks for clarifying!
Andrew
|
Copyright © 1999-2021 by the D Language Foundation