[cfe-commits] r132784 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/Sema/parentheses.cpp
Frits van Bommel
fvbommel at gmail.com
Thu Jun 9 10:41:53 PDT 2011
On 9 June 2011 19:06, Hans Wennborg <hans at hanshq.net> wrote:
> Author: hans
> Date: Thu Jun 9 12:06:51 2011
> New Revision: 132784
>
> URL: http://llvm.org/viewvc/llvm-project?rev=132784&view=rev
> Log:
> Handle overloaded operators in ?: precedence warning
>
> This is a follow-up to r132565, and should address the rest of PR9969:
>
> 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...
> @@ -6243,52 +6299,36 @@
> Expr *cond,
> Expr *lhs,
> Expr *rhs) {
> - while (ImplicitCastExpr *C = dyn_cast<ImplicitCastExpr>(cond))
> - cond = C->getSubExpr();
> + BinaryOperatorKind CondOpcode;
> + Expr *CondRHS;
>
> - if (BinaryOperator *OP = dyn_cast<BinaryOperator>(cond)) {
> - if (!IsArithmeticOp(OP->getOpcode()))
> - return;
Maybe add
if (ExprLooksBoolean(cond))
return;
here?
(Actually, just 'cond->getType()->isBooleanType()' would be enough here)
Alternatively, you could put the check in IsArithmeticBinaryExpr().
That way you could only perform the check when you actually see an
overloaded operator.
> + if (!IsArithmeticBinaryExpr(cond, &CondOpcode, &CondRHS))
> + return;
> + if (!ExprLooksBoolean(CondRHS))
> + return;
More information about the cfe-commits
mailing list