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.

llvm-svn: 140036
This commit is contained in:
Matt Beaumont-Gay 2011-09-19 18:51:20 +00:00
parent 40700e0992
commit dcaacaa190
2 changed files with 19 additions and 1 deletions

View 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.
}

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