Implicit const

Janice Caron caron800 at googlemail.com
Wed Apr 2 23:59:43 PDT 2008


On 03/04/2008, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
>  However, when the compiler compiles getA, it can actually tell pretty
> easily, that, yeh, getA is really also OK as const.  So at least for such
> simple cases, it seems that the explicit labeling is not really necessary.

I've thought about this before, and it seems to me that, if D had
warnings, it would be a good call to issue a warning for any function
which /could/ have declared itself const, but didn't. Ditto any
function parameter.

Similarly,

    class C
    {
        int f()
        {
            return 42;
        }
    }

the compiler is in a position to say "Wait a minute - you could have
declared f static, but didn't".

Again, implicit attributes are not a good idea, because it's a good
idea to have the compiler check that you're enforcing the contract you
claim to be enforcing. But warnings would be useful.

...Not that D has warnings. Maybe it could be a -w feature?



More information about the Digitalmars-d mailing list