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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 30 11:05:35 PDT 2013


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


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #9 from monarchdodra at gmail.com 2013-06-30 11:05:34 PDT ---
(In reply to comment #6)
> I think "const T foo" should be parsed as "const(T) foo" where T is not void
> and be an error otherwise. (I was almost certain that former was how it has
> behaved before!)

I think that would be a horrible decision, because "const T foo" *means*
something for member functions. Your proposed change would have a different
parse meaning depending on if the function is member or not:

const T foo(); (1)
struct S
{
    const T foo(); (2)
}

Method (1) would return a const(T).
But method (2) would return a T.

As much of a surprise as it is for C++ new comers, D's "const" syntax is simply
different (and better). The word "const" all by itself is a function attribute,
and that is all it should ever be. The compiler should *help* catch such
erroneous usage, not silently ignore it.

Also, having a different behavior depending on prefix/postfix makes no sense to
me. Both are *equally* wrong, and arguably, "prefix qualifiers" have *higher*
chances of being actual mistakes. The evidence of this has already been
demonstrated in this thread, and is brought up *regularly* in learn (and even
then, only when it actually creates problems).

So we brake some code? Yes. Code that was most probably silently wrong to begin
with. This is a "good move". The error is verbose and explicit, and the fix is
trivial. Let's keep making D safe by default please (!) Let's do everyone a
favor and put a definitive *end* to this mess.

-- 
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