r208824 - When an overloaded comparison operator returns a reference, do not consider
Richard Trieu
rtrieu at google.com
Wed May 14 16:22:10 PDT 2014
Author: rtrieu
Date: Wed May 14 18:22:10 2014
New Revision: 208824
URL: http://llvm.org/viewvc/llvm-project?rev=208824&view=rev
Log:
When an overloaded comparison operator returns a reference, do not consider
it for -Wunused-comparion warnings. This fixes PR19724.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/warn-unused-comparison.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=208824&r1=208823&r2=208824&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed May 14 18:22:10 2014
@@ -2094,6 +2094,8 @@ bool Expr::isUnusedResultAWarning(const
case OO_Greater:
case OO_GreaterEqual:
case OO_LessEqual:
+ if (Op->getCallReturnType()->isReferenceType())
+ break;
WarnE = this;
Loc = Op->getOperatorLoc();
R1 = Op->getSourceRange();
Modified: cfe/trunk/test/SemaCXX/warn-unused-comparison.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-comparison.cpp?rev=208824&r1=208823&r2=208824&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-comparison.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-comparison.cpp Wed May 14 18:22:10 2014
@@ -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}}
+}
+}
More information about the cfe-commits
mailing list