diff options
| author | Richard Trieu <rtrieu@google.com> | 2014-05-14 23:22:10 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2014-05-14 23:22:10 +0000 |
| commit | 161132b95b18023ad82606b63091969b7121da69 (patch) | |
| tree | 0f1d4ce680c9c8fc071c34066082f7b7af0118ce | |
| parent | 73bd03cee965b861c528f3259fea1b086f2c10bc (diff) | |
| download | bcm5719-llvm-161132b95b18023ad82606b63091969b7121da69.tar.gz bcm5719-llvm-161132b95b18023ad82606b63091969b7121da69.zip | |
When an overloaded comparison operator returns a reference, do not consider
it for -Wunused-comparion warnings. This fixes PR19724.
llvm-svn: 208824
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-unused-comparison.cpp | 13 |
2 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 6d8b165e715..f51e188b416 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2094,6 +2094,8 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, case OO_Greater: case OO_GreaterEqual: case OO_LessEqual: + if (Op->getCallReturnType()->isReferenceType()) + break; WarnE = this; Loc = Op->getOperatorLoc(); R1 = Op->getSourceRange(); diff --git a/clang/test/SemaCXX/warn-unused-comparison.cpp b/clang/test/SemaCXX/warn-unused-comparison.cpp index 8e6f0f49f19..505f58b39d0 100644 --- a/clang/test/SemaCXX/warn-unused-comparison.cpp +++ b/clang/test/SemaCXX/warn-unused-comparison.cpp @@ -106,3 +106,16 @@ namespace PR10291 { X<int> x; } + +namespace PR19724 { +class stream { +} cout, cin; + +stream &operator<(stream &s, int); +bool operator<(stream &s, stream &s2); + +void test() { + cout < 5; // no waring, operator returns a reference + cout < cin; // expected-warning {{relational comparison result unused}} +} +} |

