diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-08-17 09:49:44 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-08-17 09:49:44 +0000 |
commit | 463394752b931bb995faf5516eb3337f4a46c3c5 (patch) | |
tree | f502a930962ad6043a90d6c116d4cb17ae380df9 /clang/lib/AST/Expr.cpp | |
parent | e2669397f1cfd2b444bef9c6ab875367e0a63d75 (diff) | |
download | bcm5719-llvm-463394752b931bb995faf5516eb3337f4a46c3c5.tar.gz bcm5719-llvm-463394752b931bb995faf5516eb3337f4a46c3c5.zip |
Whitelist operator== and operator!= as valid for unused value warnings,
even when overloaded and user-defined. These operators are both more
valuable to warn on (due to likely typos) and extremely unlikely to be
reasonable for use to trigger side-effects.
llvm-svn: 137823
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r-- | clang/lib/AST/Expr.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 5e795be56d1..41fa850184e 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1524,8 +1524,21 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); return true; + case CXXOperatorCallExprClass: { + // We warn about operator== and operator!= even when user-defined operator + // overloads as there is no reasonable way to define these such that they + // have non-trivial, desirable side-effects. See the -Wunused-comparison + // warning: these operators are commonly typo'ed, and so warning on them + // provides additional value as well. If this list is updated, + // DiagnoseUnusedComparison should be as well. + const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); + if (Op->getOperator() == OO_EqualEqual || + Op->getOperator() == OO_ExclaimEqual) + return true; + + // Fallthrough for generic call handling. + } case CallExprClass: - case CXXOperatorCallExprClass: case CXXMemberCallExprClass: { // If this is a direct call, get the callee. const CallExpr *CE = cast<CallExpr>(this); |