Fix a crash when a pointer-to-member function is called in the condition

expression of '?:'. Add a test case for this pattern, and also test the
code that led to the crash in a "working" case as well.

llvm-svn: 133523
This commit is contained in:
Chandler Carruth 2011-06-21 17:22:09 +00:00
parent 083f0b5a7e
commit 4352b0b876
2 changed files with 15 additions and 1 deletions

View File

@ -2045,7 +2045,7 @@ Expr *Expr::IgnoreParenImpCasts() {
Expr *Expr::IgnoreConversionOperator() {
if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) {
if (isa<CXXConversionDecl>(MCE->getMethodDecl()))
if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl()))
return MCE->getImplicitObjectArgument();
}
return this;

View File

@ -29,3 +29,17 @@ void f(Stream& s, bool b) {
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
// expected-note {{place parentheses around the '<<' expression to silence this warning}}
}
struct S {
operator int() { return 42; }
friend S operator+(const S &lhs, bool) { return S(); }
};
void test(S *s, bool (S::*m_ptr)()) {
(void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
// expected-note {{place parentheses around the '+' expression to silence this warning}}
// Don't crash on unusual member call expressions.
(void)((s->*m_ptr)() ? "foo" : "bar");
}