[cfe-commits] r132784 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/Sema/parentheses.cpp

Chandler Carruth chandlerc at google.com
Thu Jun 9 10:48:30 PDT 2011


On Thu, Jun 9, 2011 at 10:41 AM, Frits van Bommel <fvbommel at gmail.com>wrote:

> > Warn about cases such as
> >
> > int foo(A a, bool b) {
> >  return a + b ? 1 : 2; // user probably meant a + (b ? 1 : 2);
> > }
> >
> > also when + is an overloaded operator call.
>
> What happens when someone is silly enough to overloads an arithmetic
> operator to return bool?
> Sure it's not a good idea, but maybe you shouldn't produce *this*
> warning in that case...


If you're imagining the "+" above is an operator returning a bool, I *still*
think we should warn here, and require ()s around the condition expression
to silence the warning. Other readers of the code will likely be surprised
at this being the intended behavior.

The warning includes one fixit hint option which makes exactly that
transformation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110609/58641e32/attachment.html>


More information about the cfe-commits mailing list