Thread overview | |||||
---|---|---|---|---|---|
|
January 12, 2011 Struct constructors callable twice? | ||||
---|---|---|---|---|
| ||||
Attachments:
| I've found this behavior while toying with opCall() in a struct:
import std.stdio;
struct Struct
{
this(int value) { writeln("Struct.this(", value, ")"); }
~this() { writeln("Struct.~this()"); }
}
void main()
{
Struct s = Struct(1); // prints `Struct.this(1)`
s(2); // prints `Struct.this(2)`
s(3); // prints `Struct.this(3)`
} // prints `Struct.~this()`
Notice how the destructor is only called once. If there was an opCall defined for Struct, its reconstruction would shadow it. It certainly looks like a bug to me, but since I'm "sure of nothing" in D I decided to post it here. Is it really a bug?
--
Atenciosamente / Sincerely,
Guilherme ("n2liquid") Vieira
|
January 12, 2011 Re: Struct constructors callable twice? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Guilherme Vieira | See also: http://d.puremagic.com/issues/show_bug.cgi?id=4053 Bye, bearophile |
January 12, 2011 Re: Struct constructors callable twice? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile Attachments:
| Yes, it was meddling with that bug that I cooked this one.
I think Adam got it right: "There should be no problem between an instance opCall and a constructor". In your case, it seems, a static opCall was clashing with the constructor. But it turns out a non-static opCall clashes with a constructor that AFAIK shouldn't even be there (see my initial post).
--
Atenciosamente / Sincerely,
Guilherme ("n2liquid") Vieira
On Wed, Jan 12, 2011 at 10:12 AM, bearophile <bearophileHUGS@lycos.com>wrote:
> See also: http://d.puremagic.com/issues/show_bug.cgi?id=4053
>
> Bye,
> bearophile
|
Copyright © 1999-2021 by the D Language Foundation