<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>You can't apply them, but you can check the output using FileCheck -fdiagnostics-parseable-fixits. With the @LINE support in FileCheck now this isn't too bad. You can see other tests that do this, like test/FixIt/format-darwin.m.</div><div><br></div><br><div><div>On Apr 17, 2013, at 11:55 , Richard Trieu <<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">How do you apply fix-its from notes?  The -fixit option only applies fix-its from errors and warnings.  Warnings like this typically have two notes with one fix-it each, one that changes the code and one to silence the warning.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 17, 2013 at 9:40 AM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I know it's a bit of a pain, but can you add a fix-it test to make sure we get the parens in the right place? (Obviously you tested this by hand, but just in case.)<br>

<span class="HOEnZb"><font color="#888888"><br>
Jordan<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Apr 16, 2013, at 19:12 , Richard Trieu <<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>> wrote:<br>
<br>
> Author: rtrieu<br>
> Date: Tue Apr 16 21:12:45 2013<br>
> New Revision: 179662<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=179662&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=179662&view=rev</a><br>
> Log:<br>
> Add warning group -Woverloaded-shift-op-parentheses to -Wparentheses.  This<br>
> will fire on code such as:<br>
><br>
>  cout << x == 0;<br>
><br>
> which the compiler will intrepret as<br>
><br>
>  (cout << x) == 0;<br>
><br>
> This warning comes with two fixits attached to notes, one for parentheses to<br>
> silence the warning, and another to evaluate the comparison first.<br>
><br>
> Modified:<br>
>    cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
>    cfe/trunk/lib/Sema/SemaExpr.cpp<br>
>    cfe/trunk/test/Sema/parentheses.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=179662&r1=179661&r2=179662&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=179662&r1=179661&r2=179662&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Apr 16 21:12:45 2013<br>
> @@ -122,6 +122,7 @@ def GlobalConstructors : DiagGroup<"glob<br>
> def BitwiseOpParentheses: DiagGroup<"bitwise-op-parentheses">;<br>
> def LogicalOpParentheses: DiagGroup<"logical-op-parentheses">;<br>
> def ShiftOpParentheses: DiagGroup<"shift-op-parentheses">;<br>
> +def OverloadedShiftOpParentheses: DiagGroup<"overloaded-shift-op-parentheses">;<br>
> def DanglingElse: DiagGroup<"dangling-else">;<br>
> def DanglingField : DiagGroup<"dangling-field">;<br>
> def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">;<br>
> @@ -352,6 +353,7 @@ def Parentheses : DiagGroup<"parentheses<br>
>                             [LogicalOpParentheses,<br>
>                              BitwiseOpParentheses,<br>
>                              ShiftOpParentheses,<br>
> +                             OverloadedShiftOpParentheses,<br>
>                              ParenthesesOnEquality,<br>
>                              DanglingElse]>;<br>
><br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=179662&r1=179661&r2=179662&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=179662&r1=179661&r2=179662&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 16 21:12:45 2013<br>
> @@ -4041,6 +4041,13 @@ def warn_bitwise_and_in_bitwise_or : War<br>
> def warn_logical_and_in_logical_or : Warning<<br>
>   "'&&' within '||'">, InGroup<LogicalOpParentheses>;<br>
><br>
> +def warn_overloaded_shift_in_comparison :Warning<<br>
> +  "overloaded operator %select{>>|<<}0 has lower precedence than "<br>
> +  "comparison operator">,<br>
> +  InGroup<OverloadedShiftOpParentheses>;<br>
> +def note_evaluate_comparison_first :Note<<br>
> +  "place parentheses around comparison expression to evaluate it first">;<br>
> +<br>
> def warn_addition_in_bitshift : Warning<<br>
>   "operator '%0' has lower precedence than '%1'; "<br>
>   "'%1' will be evaluated first">, InGroup<ShiftOpParentheses>;<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=179662&r1=179661&r2=179662&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=179662&r1=179661&r2=179662&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Apr 16 21:12:45 2013<br>
> @@ -8877,6 +8877,33 @@ static void DiagnoseAdditionInShift(Sema<br>
>   }<br>
> }<br>
><br>
> +static void DiagnoseShiftCompare(Sema &S, SourceLocation OpLoc,<br>
> +                                 Expr *LHSExpr, Expr *RHSExpr) {<br>
> +  CXXOperatorCallExpr *OCE = dyn_cast<CXXOperatorCallExpr>(LHSExpr);<br>
> +  if (!OCE)<br>
> +    return;<br>
> +<br>
> +  FunctionDecl *FD = OCE->getDirectCallee();<br>
> +  if (!FD || !FD->isOverloadedOperator())<br>
> +    return;<br>
> +<br>
> +  OverloadedOperatorKind Kind = FD->getOverloadedOperator();<br>
> +  if (Kind != OO_LessLess && Kind != OO_GreaterGreater)<br>
> +    return;<br>
> +<br>
> +  S.Diag(OpLoc, diag::warn_overloaded_shift_in_comparison)<br>
> +      << LHSExpr->getSourceRange() << RHSExpr->getSourceRange()<br>
> +      << (Kind == OO_LessLess);<br>
> +  SuggestParentheses(S, OpLoc,<br>
> +                     S.PDiag(diag::note_evaluate_comparison_first),<br>
> +                     SourceRange(OCE->getArg(1)->getLocStart(),<br>
> +                                 RHSExpr->getLocEnd()));<br>
> +  SuggestParentheses(S, OCE->getOperatorLoc(),<br>
> +                     S.PDiag(diag::note_precedence_silence)<br>
> +                         << (Kind == OO_LessLess ? "<<" : ">>"),<br>
> +                     OCE->getSourceRange());<br>
> +}<br>
> +<br>
> /// DiagnoseBinOpPrecedence - Emit warnings for expressions with tricky<br>
> /// precedence.<br>
> static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc,<br>
> @@ -8905,6 +8932,11 @@ static void DiagnoseBinOpPrecedence(Sema<br>
>     DiagnoseAdditionInShift(Self, OpLoc, LHSExpr, Shift);<br>
>     DiagnoseAdditionInShift(Self, OpLoc, RHSExpr, Shift);<br>
>   }<br>
> +<br>
> +  // Warn on overloaded shift operators and comparisons, such as:<br>
> +  // cout << 5 == 4;<br>
> +  if (BinaryOperator::isComparisonOp(Opc))<br>
> +    DiagnoseShiftCompare(Self, OpLoc, LHSExpr, RHSExpr);<br>
> }<br>
><br>
> // Binary Operators.  'Tok' is the token for the operator.<br>
><br>
> Modified: cfe/trunk/test/Sema/parentheses.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.cpp?rev=179662&r1=179661&r2=179662&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.cpp?rev=179662&r1=179661&r2=179662&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/Sema/parentheses.cpp (original)<br>
> +++ cfe/trunk/test/Sema/parentheses.cpp Tue Apr 16 21:12:45 2013<br>
> @@ -29,6 +29,12 @@ void f(Stream& s, bool b) {<br>
>   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \<br>
>                                   // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \<br>
>                                   // expected-note {{place parentheses around the '<<' expression to silence this warning}}<br>
> +  (void)(s << 5 == 1); // expected-warning {{overloaded operator << has lower precedence than comparison operator}} \<br>
> +                       // expected-note {{place parentheses around the '<<' expression to silence this warning}} \<br>
> +                       // expected-note {{place parentheses around comparison expression to evaluate it first}}<br>
> +  (void)(s >> 5 == 1); // expected-warning {{overloaded operator >> has lower precedence than comparison operator}} \<br>
> +                       // expected-note {{place parentheses around the '>>' expression to silence this warning}} \<br>
> +                       // expected-note {{place parentheses around comparison expression to evaluate it first}}<br>
> }<br>
><br>
> struct S {<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>
<br>
</div></div></blockquote></div><br></div>
</blockquote></div><br></body></html>