]> granicus.if.org Git - clang/commitdiff
Fix a QoI bug with overloaded operators inside macros.
authorMatt Beaumont-Gay <matthewbg@google.com>
Mon, 19 Sep 2011 18:51:20 +0000 (18:51 +0000)
committerMatt Beaumont-Gay <matthewbg@google.com>
Mon, 19 Sep 2011 18:51:20 +0000 (18:51 +0000)
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

lib/AST/Expr.cpp
test/SemaCXX/warn-unused-value.cpp

index 8beecc0856cf8b4e3d696b5ae9236bd85a130fc1..7983d61f041e36df85b4ed1402d6dc0cb03aa86a 100644 (file)
@@ -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.
   }
index 775c3cf01f243a6cd76fdfdd4c296432bd7a6218..80298ec6664a8820f70a41c17e7ab7591dc40601 100644 (file)
@@ -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
+}