aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Beaumont-Gay <matthewbg@google.com>2011-09-19 18:51:20 +0000
committerMatt Beaumont-Gay <matthewbg@google.com>2011-09-19 18:51:20 +0000
commit6e5218367c513fe02d1c7210023d40739ecb1572 (patch)
tree029683c54d09f7faae717a71e98d4f9ba9fdcd71
parent71ac1e003b7a82ca6ac7ed76e4d0f9c6d4a1e30a (diff)
Fix a QoI bug with overloaded operators inside macros.
We were failing to set source locations and ranges in isUnusedResultAWarning for CXXOperatorCallExprs, leading to an "expression result unused" warning with absolutely no context if the expression was inside a macro. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140036 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/Expr.cpp5
-rw-r--r--test/SemaCXX/warn-unused-value.cpp15
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 8beecc0856..7983d61f04 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -1631,8 +1631,11 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
// DiagnoseUnusedComparison should be as well.
const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this);
if (Op->getOperator() == OO_EqualEqual ||
- Op->getOperator() == OO_ExclaimEqual)
+ Op->getOperator() == OO_ExclaimEqual) {
+ Loc = Op->getOperatorLoc();
+ R1 = Op->getSourceRange();
return true;
+ }
// Fallthrough for generic call handling.
}
diff --git a/test/SemaCXX/warn-unused-value.cpp b/test/SemaCXX/warn-unused-value.cpp
index 775c3cf01f..80298ec666 100644
--- a/test/SemaCXX/warn-unused-value.cpp
+++ b/test/SemaCXX/warn-unused-value.cpp
@@ -15,3 +15,18 @@ namespace test0 {
box->j;
}
}
+
+namespace test1 {
+struct Foo {
+ int i;
+ bool operator==(const Foo& rhs) {
+ return i == rhs.i;
+ }
+};
+
+#define NOP(x) (x)
+void b(Foo f1, Foo f2) {
+ NOP(f1 == f2); // expected-warning {{expression result unused}}
+}
+#undef NOP
+}