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

Dominique Devienne via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 6 12:07:38 PST 2015


On Fri, Nov 6, 2015 at 7:08 PM, Richard via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> There seems to be a certain breed of programmer that once having
> learned a new feature of C++ intends to get out their new feature
> hammer and bang on everything in sight.
>

I'm not native to the English language, but apparently breed is mostly
reserved to plants and animals.
I doesn't read that nice IMHO. Perhaps avoid such denomination for
programmers in the future. My $0.02.


> [... ] In other words, this code would be left alone:
>
> template <typename T, typename U>
> auto add(T x, U y) -> decltype(x + y)
> {
>   return x + y;
> }
>
> There is one note in N2541 that states how the new syntax eliminates
> an ambiguity with this example:
>
> auto f() -> int (*)[4];
> // function returning a pointer to array[4] of int,
> // not function returning array[4] of pointer to int.
>
> This seems to be another case that should be left unchanged.
>

In

struct Outer {
  struct Inner {};
  Inner getInner() { ... }
};

Instead of writing

Outer::Inner Outer::getInner() { ... }

I noticed that I can now write

auto Outer::getInner() -> Inner { ... }

If Outer is a long type name, not having to repeat it is kinda nice.
Of course client code must use Outer::Inner, unless it itself uses auto...

Similarly, in

template <typename TPrivilege>
auto PrivilegeSet<TPrivilege>::insert(const value_type& val)
  -> std::pair<iterator, bool>
{ ... }

iterator is a nested type, and not having to qualify it, nor using
typename, thanks to trailing return, is "nice" IMHO.

So am I "one of those people" with the above, or this is acceptable to you?
--DD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151106/0e558729/attachment.html>


More information about the cfe-dev mailing list