]> granicus.if.org Git - clang/commitdiff
Evaluation support for ExprWithCleanups. We won't evaluate any expression which
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 19 Dec 2011 22:12:41 +0000 (22:12 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 19 Dec 2011 22:12:41 +0000 (22:12 +0000)
actually requires non-trivial cleanups, so no cleanups need to be performed.

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

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx11.cpp

index 630136ea7f862465f8615c3140ee0a6af9417929..3c2ffbd0f7b3397785a43796c410546f948b7ab0 100644 (file)
@@ -1799,6 +1799,10 @@ public:
     { return StmtVisitorTy::Visit(E->getReplacement()); }
   RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
     { return StmtVisitorTy::Visit(E->getExpr()); }
+  // We cannot create any objects for which cleanups are required, so there is
+  // nothing to do here; all cleanups must come from unevaluated subexpressions.
+  RetTy VisitExprWithCleanups(const ExprWithCleanups *E)
+    { return StmtVisitorTy::Visit(E->getSubExpr()); }
 
   RetTy VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
     CCEDiag(E, diag::note_constexpr_invalid_cast) << 0;
index e4ada1ed832d275362016cc59ff1126184a6201f..5798eb594852fbabc596942c9a5c3ce9772bf945 100644 (file)
@@ -923,3 +923,9 @@ namespace PR11595 {
   }
   constexpr int n = f(1); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'f(1)'}}
 }
+
+namespace ExprWithCleanups {
+  struct A { A(); ~A(); int get(); };
+  constexpr int get(bool FromA) { return FromA ? A().get() : 1; }
+  constexpr int n = get(false);
+}