<div dir="ltr">While this seems like a good idea, perhaps the tidy it should examine the complexity of the type being "auto"ed. The new return value syntax seems good to move a long type to the end of a function declaration to help code clarity, even if it is not strictly necessary.<div><br></div><div>auto f() -> my_super_duper<long,long,long,long,long> {</div><div>  ...</div><div>}</div><div><br></div><div>A simple type name (e.g., int or Airplane) seems okay to do the proposed refactoring, beyond that seems less of a clarity win to me.</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 6, 2015 at 1:08 PM, Richard via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[Please reply *only* to the list and do not include my email directly<br>
in the To: or Cc: of your reply; otherwise I will not see your reply.<br>
Thanks.]<br>
<br>
Hello tidy programmers,<br>
<br>
There seems to be a certain breed of programmer that once having<br>
learned a new feature of C++ intends to get out their new feature<br>
hammer and bang on everything in sight.<br>
<br>
Case in point:<br>
<br>
N2541 <<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm" rel="noreferrer" target="_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm</a>><br>
introduced auto and the trailing return type syntax.<br>
<br>
Now people are using auto and -> on function signatures where the<br>
return type is stated explicitly anyway.  This results in code like:<br>
<br>
auto main() -> int<br>
{<br>
  return 0;<br>
}<br>
<br>
Srsly?  Is this really improving anything over<br>
<br>
int main()<br>
{<br>
  return 0;<br>
}<br>
<br>
To me this is introducing unnecessary clutter and isn't the reason why<br>
auto and -> for function return types were introduced.<br>
<br>
I would like to propose a clang-tidy readability check that turns the<br>
former into the latter when the return type doesn't use anything that<br>
needs auto.  In other words, this code would be left alone:<br>
<br>
template <typename T, typename U><br>
auto add(T x, U y) -> decltype(x + y)<br>
{<br>
  return x + y;<br>
}<br>
<br>
There is one note in N2541 that states how the new syntax eliminates<br>
an ambiguity with this example:<br>
<br>
auto f() -> int (*)[4];<br>
// function returning a pointer to array[4] of int,<br>
// not function returning array[4] of pointer to int.<br>
<br>
This seems to be another case that should be left unchanged.<br>
<br>
Proposed check name: readability-redundant-auto-return-type<br>
<br>
What are your thoughts?<br>
<span><font color="#888888">--<br>
"The Direct3D Graphics Pipeline" free book <<a href="http://tinyurl.com/d3d-pipeline" rel="noreferrer" target="_blank">http://tinyurl.com/d3d-pipeline</a>><br>
     The Computer Graphics Museum <<a href="http://ComputerGraphicsMuseum.org" rel="noreferrer" target="_blank">http://ComputerGraphicsMuseum.org</a>><br>
         The Terminals Wiki <<a href="http://terminals.classiccmp.org" rel="noreferrer" target="_blank">http://terminals.classiccmp.org</a>><br>
  Legalize Adulthood! (my blog) <<a href="http://LegalizeAdulthood.wordpress.com" rel="noreferrer" target="_blank">http://LegalizeAdulthood.wordpress.com</a>><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Tim Halloran<br>SureLogic, Inc.<br>5808 Forbes Avenue, Pittsburgh PA 15217-1602<br><a href="tel:%28412%29%20722-3338" value="+14127223338" target="_blank">(412) 722-3338</a></div>
</div></div>