<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr"><div class="gmail_default" style>The CL description is not precise enough (see patch). The unary operators we use are: +, ++, -, --, !, ~ and alignof. Also there is a precedence in the detection, so it actually formats:</div>
<div class="gmail_default" style><br></div><div class="gmail_default" style>int* a = *++i;</div><div class="gmail_default" style><br></div><div class="gmail_default" style>I am sure there are still cases we are missing, but this should be an improvement. Feel free to file further bugs.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 2, 2013 at 6:47 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, Jan 2, 2013 at 9:21 AM, Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:<br>
> Author: djasper<br>
> Date: Wed Jan 2 11:21:36 2013<br>
> New Revision: 171396<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=171396&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=171396&view=rev</a><br>
> Log:<br>
> Format */& as binary operator if followed by a unary operator.<br>
<br>
</div>That doesn't quite sound correct - what about cases where */& are<br>
actually unary operators even when they're followed by another unary<br>
operator?<br>
<br>
iter x;<br>
func(&*x);<br>
<br>
void func(int **x) {<br>
**x = 3;<br>
}<br>
<br>
etc... (certainly *++x wouldn't be too uncommon, again with iterators,<br>
but any combination could be possible with arbitrary operator<br>
overloads, though I'm not sure how much you want/need to bother<br>
accounting for that kind of code)<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> This fixes <a href="http://llvm.org/PR14687" target="_blank">llvm.org/PR14687</a>.<br>
> Also fixes segfault for lines starting with * or &.<br>
><br>
> Before:<br>
> a *~b;<br>
> *a = 1; // <- this segfaulted<br>
><br>
> After:<br>
> a * ~b;<br>
> *a = 1; // no segfault :-)<br>
><br>
> Modified:<br>
> cfe/trunk/lib/Format/Format.cpp<br>
> cfe/trunk/unittests/Format/FormatTest.cpp<br>
><br>
> Modified: cfe/trunk/lib/Format/Format.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=171396&r1=171395&r2=171396&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=171396&r1=171395&r2=171396&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Format/Format.cpp (original)<br>
> +++ cfe/trunk/lib/Format/Format.cpp Wed Jan 2 11:21:36 2013<br>
> @@ -835,19 +835,23 @@<br>
> }<br>
><br>
> TokenAnnotation::TokenType determineStarAmpUsage(unsigned Index, bool IsRHS) {<br>
> + if (Index == 0)<br>
> + return TokenAnnotation::TT_UnaryOperator;<br>
> if (Index == Annotations.size())<br>
> return TokenAnnotation::TT_Unknown;<br>
> const FormatToken &PrevToken = Line.Tokens[Index - 1];<br>
> const FormatToken &NextToken = Line.Tokens[Index + 1];<br>
><br>
> - if (Index == 0 || <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::l_paren) ||<br>
> - <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::comma) || <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::kw_return) ||<br>
> - <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::colon) ||<br>
> + if (<a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::l_paren) || <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::comma) ||<br>
> + <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::kw_return) || <a href="http://PrevToken.Tok.is" target="_blank">PrevToken.Tok.is</a>(tok::colon) ||<br>
> Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator)<br>
> return TokenAnnotation::TT_UnaryOperator;<br>
><br>
> if (PrevToken.Tok.isLiteral() || NextToken.Tok.isLiteral() ||<br>
> - <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::kw_sizeof))<br>
> + <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::plus) || <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::minus) ||<br>
> + <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::plusplus) || <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::minusminus) ||<br>
> + <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::tilde) || <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::exclaim) ||<br>
> + <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::kw_alignof) || <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::kw_sizeof))<br>
> return TokenAnnotation::TT_BinaryOperator;<br>
><br>
> if (<a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::comma) || <a href="http://NextToken.Tok.is" target="_blank">NextToken.Tok.is</a>(tok::r_paren) ||<br>
> @@ -931,7 +935,7 @@<br>
> return Left.is(tok::kw_if) || Left.is(tok::kw_for) ||<br>
> Left.is(tok::kw_while) || Left.is(tok::kw_switch) ||<br>
> (Left.isNot(tok::identifier) && Left.isNot(tok::kw_sizeof) &&<br>
> - Left.isNot(tok::kw_typeof));<br>
> + Left.isNot(tok::kw_typeof) && Left.isNot(tok::kw_alignof));<br>
> }<br>
> return true;<br>
> }<br>
><br>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171396&r1=171395&r2=171396&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171396&r1=171395&r2=171396&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 2 11:21:36 2013<br>
> @@ -28,6 +28,7 @@<br>
> CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));<br>
> LangOptions LangOpts;<br>
> LangOpts.CPlusPlus = 1;<br>
> + LangOpts.CPlusPlus11 = 1;<br>
> Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources, LangOpts);<br>
> tooling::Replacements Replace =<br>
> reformat(Style, Lex, Context.Sources, Ranges);<br>
> @@ -676,7 +677,9 @@<br>
> verifyFormat("a-- > b;");<br>
> verifyFormat("b ? -a : c;");<br>
> verifyFormat("n * sizeof char16;");<br>
> + verifyFormat("n * alignof char16;");<br>
> verifyFormat("sizeof(char);");<br>
> + verifyFormat("alignof(char);");<br>
><br>
> verifyFormat("return -1;");<br>
> verifyFormat("switch (a) {\n"<br>
> @@ -724,6 +727,13 @@<br>
> verifyFormat("return a & ~b;");<br>
> verifyFormat("f(b ? *c : *d);");<br>
> verifyFormat("int a = b ? *c : *d;");<br>
> + verifyFormat("*b = a;");<br>
> + verifyFormat("a * ~b;");<br>
> + verifyFormat("a * !b;");<br>
> + verifyFormat("a * +b;");<br>
> + verifyFormat("a * -b;");<br>
> + verifyFormat("a * ++b;");<br>
> + verifyFormat("a * --b;");<br>
><br>
> // FIXME: Is this desired for LLVM? Fix if not.<br>
> verifyFormat("A<int *> a;");<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>