When an overloaded comparison operator returns a reference, do not consider

it for -Wunused-comparion warnings.  This fixes PR19724.

llvm-svn: 208824
This commit is contained in:
Richard Trieu 2014-05-14 23:22:10 +00:00
parent 73bd03cee9
commit 161132b95b
2 changed files with 15 additions and 0 deletions

View File

@ -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();

View File

@ -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}}
}
}