]> granicus.if.org Git - clang/commitdiff
Fix a crash when a pointer-to-member function is called in the condition
authorChandler Carruth <chandlerc@gmail.com>
Tue, 21 Jun 2011 17:22:09 +0000 (17:22 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 21 Jun 2011 17:22:09 +0000 (17:22 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133523 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/Sema/parentheses.cpp

index 31972bdd23e044692a697076e1e8f52557340531..1faceb9425811646c7b101d5d98bfa9e5966b1d3 100644 (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;
index c14a671292bf1fa929085e577e767774f64235cf..252455dcad491031e33ab1260aceeed3c47a0ea9 100644 (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");
+}