const(Object)ref is here!

spir denis.spir at gmail.com
Mon Dec 6 23:32:11 PST 2010


On Mon, 6 Dec 2010 15:01:25 -0500
Michel Fortin <michel.fortin at michelf.com> wrote:

> On 2010-12-06 14:46:51 -0500, spir <denis.spir at gmail.com> said:
> 
> > On Mon, 6 Dec 2010 13:44:41 -0500
> > Michel Fortin <michel.fortin at michelf.com> wrote:
> > 
> >> Since we're speaking of the optional use of 'ref', here's a little quiz:
> >> 
> >> 	alias Object A;
> >> 	alias Object ref B;
> >> 
> >> 	A ref a;
> >> 	B ref b;
> >> 
> >> What happens here? Should there be an error somewhere? Where? Also,
> >> what happens if we apply different modifiers at different places?
> > 
> > As I understand the (non-)semantics of 'ref', there should be no error. Thi
> > s code should considered by the compiler as equivalent to:
> > 	Object a;
> > 	Object b;
> 
> And that's what my patch does. It only gets confusing when you add modifiers:
> 
> 	alias const(Object)ref A;
> 	alias const(Object ref) B;
> 	alias const(Object) C;
> 
> 	A ref a;
> 	B ref b;
> 	C ref c;
> 
> With my patch, variables 'a', 'b', and 'c' are all of the same type: 
> "const(Object)ref", the later 'ref' changing the constness of the 
> reference specified in the 'B' alias.

Well, as your patch introduces the possibility to "const-en" the target of ref's, it _should_ have some meaning. Else, it leaves the language unconsistent, no? B & C are clearly synonym (constant references to objects), but A should not (references to constant objects). I see nothing wrong in having a type defined as one for <references to constant objects>, and in having this different from <constant references to objects>. Do I miss some point?

> [...]


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list