<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 22, 2015 at 2:11 PM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@hanshq.net" target="_blank">hans@hanshq.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: hans<br>
Date: Thu Jan 22 16:11:56 2015<br>
New Revision: 226870<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226870&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=226870&view=rev</a><br>
Log:<br>
Make the ?: precedence warning handle pointers to the left of ?<br>
<br>
Previously, Clang would fail to warn on:<br>
<br>
  int n = x + foo ? 1 : 2;<br>
<br>
when foo is a pointer.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaExpr.cpp<br>
    cfe/trunk/test/Sema/parentheses.c<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=226870&r1=226869&r2=226870&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=226870&r1=226869&r2=226870&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jan 22 16:11:56 2015<br>
@@ -6129,6 +6129,8 @@ static bool ExprLooksBoolean(Expr *E) {<br>
     return IsLogicOp(OP->getOpcode());<br>
   if (UnaryOperator *OP = dyn_cast<UnaryOperator>(E))<br>
     return OP->getOpcode() == UO_LNot;<br>
+  if (E->getType()->isPointerType())<br></blockquote><div><br>Could we generalize this a bit further, somehow? (I haven't looked at the code in question, but it sounds like this should use some more general tool of "try to apply contextual conversion to bool" so that it matches the actual semantic situation we're interested in here)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    return true;<br>
<br>
   return false;<br>
 }<br>
<br>
Modified: cfe/trunk/test/Sema/parentheses.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.c?rev=226870&r1=226869&r2=226870&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.c?rev=226870&r1=226869&r2=226870&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/parentheses.c (original)<br>
+++ cfe/trunk/test/Sema/parentheses.c Thu Jan 22 16:11:56 2015<br>
@@ -80,7 +80,7 @@ void bitwise_rel(unsigned i) {<br>
<br>
 _Bool someConditionFunc();<br>
<br>
-void conditional_op(int x, int y, _Bool b) {<br>
+void conditional_op(int x, int y, _Bool b, void* p) {<br>
   (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \<br>
                                            // expected-note {{place parentheses around the '+' expression to silence this warning}} \<br>
                                            // expected-note {{place parentheses around the '?:' expression to evaluate it first}}<br>
@@ -116,6 +116,14 @@ void conditional_op(int x, int y, _Bool<br>
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:24-[[@LINE-6]]:24}:")"<br>
<br>
   (void)(x % 2 ? 1 : 2); // no warning<br>
+<br>
+  (void)(x + p ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}<br>
+  (void)(p + x ? 1 : 2); // no warning<br>
+<br>
+  (void)(p + b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}<br>
+<br>
+  (void)(x + y > 0 ? 1 : 2); // no warning<br>
+  (void)(x + (y > 0) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}<br>
 }<br>
<br>
 // RUN: not %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s -check-prefix=CHECK-FLAG<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>
</blockquote></div><br></div></div>