From 65dd6234cb748bd3a8cfd1e3aa84fffc2226d7e4 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 6 Feb 2014 23:35:16 +0000 Subject: [PATCH] Temporary fix for PR18473: Don't try to evaluate the initializer for a type-dependent variable, even if the initializer isn't value-dependent. This happens for ParenListExprs composed of non-value-dependent subexpressions, for instance. We should really give ParenListExprs (and InitListExprs) the type of the initialized entity if they're used to represent a dependent initialization (and if so, set them to be type-, value- and instantiation-dependent). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200954 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprCXX.cpp | 13 ++++++------- test/SemaCXX/lambda-expressions.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 8664ef9649..d43f17017a 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -5815,17 +5815,16 @@ static inline bool VariableCanNeverBeAConstantExpression(VarDecl *Var, assert(DefVD); if (DefVD->isWeak()) return false; EvaluatedStmt *Eval = DefVD->ensureEvaluatedStmt(); - + Expr *Init = cast(Eval->Value); if (Var->getType()->isDependentType() || Init->isValueDependent()) { - if (!Init->isValueDependent()) - return !DefVD->checkInitIsICE(); - // FIXME: We might still be able to do some analysis of Init here - // to conclude that even in a dependent setting, Init can never - // be a constexpr - but for now admit agnosticity. + // FIXME: Teach the constant evaluator to deal with the non-dependent parts + // of value-dependent expressions, and use it here to determine whether the + // initializer is a potential constant expression. return false; - } + } + return !IsVariableAConstantExpression(Var, Context); } diff --git a/test/SemaCXX/lambda-expressions.cpp b/test/SemaCXX/lambda-expressions.cpp index 018df002db..8bacc0aa64 100644 --- a/test/SemaCXX/lambda-expressions.cpp +++ b/test/SemaCXX/lambda-expressions.cpp @@ -344,3 +344,18 @@ namespace PR18128 { int d = []{ return [=]{ return n; }(); }(); // expected-error {{'this' cannot be implicitly captured in this context}} }; } + +namespace PR18473 { + template void f() { + T t(0); + (void) [=]{ int n = t; }; // expected-error {{deleted}} + } + + template void f(); + struct NoCopy { + NoCopy(int); + NoCopy(const NoCopy &) = delete; // expected-note {{deleted}} + operator int() const; + }; + template void f(); // expected-note {{instantiation}} +} -- 2.40.0