<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - -Wparentheses could give a smarter diagnostic if one of the operators is bitwise & or | and the operands have type `bool`"
href="https://llvm.org/bugs/show_bug.cgi?id=25769">25769</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wparentheses could give a smarter diagnostic if one of the operators is bitwise & or | and the operands have type `bool`
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>richard-llvm@metafoo.co.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, rtrieu@google.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Today I saw this:
tools/clang/lib/AST/ExprConstant.cpp:8866:49: warning: & has lower precedence
than <; < will be evaluated first [-Wparentheses]
(SEK < Expr::SE_AllowUndefinedBehavior & Result.HasUndefinedBehavior);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
tools/clang/lib/AST/ExprConstant.cpp:8866:49: note: place parentheses around
the '<' expression to silence this warning
(SEK < Expr::SE_AllowUndefinedBehavior & Result.HasUndefinedBehavior);
^
( )
tools/clang/lib/AST/ExprConstant.cpp:8866:49: note: place parentheses around
the & expression to evaluate it first
(SEK < Expr::SE_AllowUndefinedBehavior & Result.HasUndefinedBehavior);
^
( )
This is pretty good, but we could be smarter here: we have a bitwise & operator
where both operands are of type 'bool'. In that case, we should guess that the
user did actually mean an 'and' operator, and suggest changing it to '&&'
(unless the RHS has side-effects, in which case maybe suggesting parens is the
right thing).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>