[PATCH] D54877: Update coding guidelines regarding use of `auto`

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 25 09:35:26 PST 2018


lebedev.ri added a comment.

There was also this cover letter:
https://lists.llvm.org/pipermail/llvm-dev/2018-November/127953.html

> but generally leaves the rest up to the reviewer, not the contributor.

Exactly, like it should. If the reviewer can't read the code,
then the review will essentially not happen, and the bugs will be missed.



================
Comment at: docs/CodingStandards.rst:786-791
 Use ``auto`` Type Deduction to Make Code More Readable
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Some are advocating a policy of "almost always ``auto``" in C++11, however LLVM
-uses a more moderate stance. Use ``auto`` if and only if it makes the code more
-readable or easier to maintain. Don't "almost always" use ``auto``, but do use
-``auto`` with initializers like ``cast<Foo>(...)`` or other places where the
-type is already obvious from the context. Another time when ``auto`` works well
-for these purposes is when the type would have been abstracted away anyways,
-often behind a container's typedef such as ``std::vector<T>::iterator``.
+uses a more moderate stance. Don't "almost always" use ``auto``, but here are
+some cases where use of ``auto`` would make sense:
----------------
Note the subject of the paragraph.
It's not about the code being readable to the author.
It's about code readability for the review/reviewers.

Unbanning more use-cases will not make `auto` in those cases less opaque.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54877/new/

https://reviews.llvm.org/D54877





More information about the llvm-commits mailing list