Add a missing check before trying to evaluate a temporary.  PR11595.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146813 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 31b211e..0d32ebf 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -2066,6 +2066,9 @@
         return false;
       BaseTy = E->getBase()->getType()->getAs<PointerType>()->getPointeeType();
     } else if (E->getBase()->isRValue()) {
+      if (!E->getBase()->getType()->isRecordType() ||
+          !E->getBase()->getType()->isLiteralType())
+        return false;
       if (!EvaluateTemporary(E->getBase(), Result, this->Info))
         return false;
       BaseTy = E->getBase()->getType();
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp
index 5105418..5b053e4 100644
--- a/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/test/SemaCXX/constant-expression-cxx11.cpp
@@ -919,3 +919,9 @@
 static_assert(makeComplexWrap(1,0) != complex(0, 1), "");
 
 }
+
+namespace PR11595 {
+  struct A { constexpr bool operator==(int x) { return true; } };
+  struct B { B(); ~B(); A& x; };
+  static_assert(B().x == 3, "");  // expected-error {{constant expression}}
+}