diff options
| -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}} +} +} |

