[cfe-commits] r133523 - in /cfe/trunk: lib/AST/Expr.cpp test/Sema/parentheses.cpp

Chandler Carruth chandlerc at gmail.com
Tue Jun 21 10:22:10 PDT 2011


Author: chandlerc
Date: Tue Jun 21 12:22:09 2011
New Revision: 133523

URL: http://llvm.org/viewvc/llvm-project?rev=133523&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/Sema/parentheses.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=133523&r1=133522&r2=133523&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Jun 21 12:22:09 2011
@@ -2045,7 +2045,7 @@
 
 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;

Modified: cfe/trunk/test/Sema/parentheses.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.cpp?rev=133523&r1=133522&r2=133523&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.cpp (original)
+++ cfe/trunk/test/Sema/parentheses.cpp Tue Jun 21 12:22:09 2011
@@ -29,3 +29,17 @@
                                   // 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");
+}





More information about the cfe-commits mailing list