[cfe-commits] r146813 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp

Eli Friedman eli.friedman at gmail.com
Fri Dec 16 18:24:22 PST 2011


Author: efriedma
Date: Fri Dec 16 20:24:21 2011
New Revision: 146813

URL: http://llvm.org/viewvc/llvm-project?rev=146813&view=rev
Log:
Add a missing check before trying to evaluate a temporary.  PR11595.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=146813&r1=146812&r2=146813&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Dec 16 20:24:21 2011
@@ -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();

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=146813&r1=146812&r2=146813&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Fri Dec 16 20:24:21 2011
@@ -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}}
+}





More information about the cfe-commits mailing list