Read-only property without @property
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 26 18:20:46 PDT 2014
On Fri, Sep 26, 2014 at 05:35:20PM -0700, Andrei Alexandrescu via Digitalmars-d wrote:
> On 9/26/14, 4:32 PM, Steven Schveighoffer wrote:
> >On 9/26/14 6:32 PM, H. S. Teoh via Digitalmars-d wrote:
> >
> >>Does the compiler infer it as @safe, though?
> >
> >Hm... good point, I'm not sure if unions are considered @safe. But I
> >think that would be a decent enhancement request if not.
>
> I'd say certain unions may be deemed safe. -- Andrei
Hmm. I tried playing with the idea of unions being safe if all members
have the same unqualified type, but quickly ran into some nasty cases:
union U {
void delegate() @system sysDg;
void delegate() @safe safeDg;
}
Is this union @safe or not? Technically, it should be, since there's no
possibility of getting an invalid pointer to delegate using U. However,
it also breaks @safe-ty if you assign U.sysDg and call U.safeDg. (This
is currently accepted by the compiler, btw. In @safe code.)
And what of:
union U {
immutable int x;
int y;
}
? This one breaks the type system. It's certainly @safe, but has other
issues. (The compiler happily accepts this one, BTW.)
I think bug reports are in order. :-)
There's also the question of what to do with class references:
class Base {}
class Derived : Base {}
union U {
Base b;
Derived d; // fortunately, the compiler rejects this
}
I'm sure there are many more such tricky corner cases that people can
dream up if they only use their imagination a little.
T
--
"Maybe" is a strange word. When mom or dad says it it means "yes", but when my big brothers say it it means "no"! -- PJ jr.
More information about the Digitalmars-d
mailing list