When you try to use type inference on a const member function, you get a compiler error: class Foo { public: auto foo() const { return 0; } } Compiling gives: test.d(4): no identifier for declarator foo test.d(4): semicolon expected, not 'const' test.d(4): Declaration expected, not 'return' Removing the 'const' allows it to compile, but the function can no longer be called on const objects. The same applies for structs and @property methods. This is using DMD 2.049.
This is because const and auto are both storage classes. What you want is easily achieved by using this syntax: class Foo { public: const foo( ) { return 0; } }
Oh, I would have never expected that. Thanks.
But given its counter-intuitiveness, surely this is just a quirk of the grammar, and not a deliberate design feature? I suppose this is really part of the quirk whereby the grammar handles auto as an attribute rather than as what it should be: a placeholder for a type.
Fixed in 2.054. https://github.com/D-Programming-Language/dmd/commit/6a15077f8189e1ef203565edaebc766446aa105b