[Issue 10150] Prefix method 'this' qualifiers should be just ignored anytime

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 1 04:54:51 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10150



--- Comment #15 from monarchdodra at gmail.com 2013-07-01 04:54:50 PDT ---
(In reply to comment #14)
> > What about:
> > 
> > --------
> > struct S
> > {
> >     const nothrow pure
> >     T foo();
> > 
> >     nothrow pure const
> >     T bar();
> > }
> > --------
> > 
> > What does (should) foo return? What about bar?
> 
> both return const(T) (at the very least, I have no idea what T is). When I am
> speaking about postfix qualifier I mean "T bar() const pure nothrow"

Well, such a change would break existing code that is correct and respects the
spec. I'm not sure changing the semantics of such code would be acceptable. D
allows attributes to be placed either prefix or postfix. Forcing "const" to
only work right hand side is a C++ holdover. There should be no difference
where you place it. If anything, I find it weird when I find code that is
written like:
"pure @property T foo() const"
Why place the const there? Put it on the left, that's where you placed
everything else...

> > The current rules are obvious: stand alone attribute => Function.
> > Simple and obvious.
> > There is no reasons for "const" to get special treatment.
> 
> No, they are more like "stand alone attribute -> function or no-op, you'd
> better be careful!". And breaks similarity with C/C++ principle.

I agree both are problem. I happen to think the better solution is that no-op
becomes explicit compile error. This is both safe, and doesn't add special
positional casing.

> And makes your
> code needlessly "Lisp-y".

Don't know lisp.

> Behaviour has been very confusing all the time but at least it slapped me into
> face every time I tried to type stuff in a more natural syntax. Not any more.

I agree we should be slapped in the face every time we type something wrong.
Currently, being slapped in the face for wrong postfix is good. Also being
slapped for wrong prefix would be better.

The solution of saying "prefix applies to return value", would be a big
interface change. Even where we to agree it is the right decision, I don't
think it could acceptable change.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list