[cfe-dev] RFC: clang-tidy readability check to reduce clutter: unnecessary use of auto and ->

Matthijs van Duin via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 12 15:54:26 PST 2015


On 12 November 2015 at 18:50, Robinson, Paul <
Paul_Robinson at playstation.sony.com> wrote:

> 'static' is much worse... in any context other than a function-local

variable, it's just a completely arbitrary we-already-had-this-reserved
> keyword. Put it on a file-level variable, and it determines... visibility!
> Put it on a class method, and... something with no one-word description
> happens!  There really is no possible English definition of 'static' that
> could apply to either of those cases.
>

Well, if I squint a bit I can see a connection between its use in functions
and in classes, but its effect in file-scope is really unrelated indeed.
The biggest irony that their its use inside functions/classes makes the
declaration behave (except for the scoping of its name) as if it were a
declaration at file scope, but *not* a static one there!

'auto' applied to a return-type could at least be interpreted as
> "automatically decide what this type is"


Except support for return-type inference is more recent than support for
using 'auto' to introduce the trailing return type syntax. There's
technically actually therefore now ambiguity between those two uses of the
keyword, disambiguated by the presence or absence of an actual trailing
return type.

You can of course also combine them, i.e.
let foo( ... ) -> auto { ... }

Although I have to say, 'let' has some appeal.


I think it's really remarkable how well it fits and natural it feels, far
more so than 'auto' (at least to me; I may be biased due to exposure to
languages like OCaml).

Matthijs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151113/c3f5d3bb/attachment.html>


More information about the cfe-dev mailing list