From 42b10572443e3f3f3c4a113f88ad4e9b504df900 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 11 Nov 2015 01:36:17 +0000 Subject: N3922: direct-list-initialization of an auto-typed variable no longer deduces a std::initializer_list type. Instead, the list must contain a single element and the type is deduced from that. In Clang 3.7, we warned by default on all the cases that would change meaning due to this change. In Clang 3.8, we will support only the new rules -- per the request in N3922, this change is applied as a Defect Report against earlier versions of the C++ standard. This change is not entirely trivial, because for lambda init-captures we previously did not track the difference between direct-list-initialization and copy-list-initialization. The difference was not previously observable, because the two forms of initialization always did the same thing (the elements of the initializer list were always copy-initialized regardless of the initialization style used for the init-capture). llvm-svn: 252688 --- clang/lib/Parse/ParseExprCXX.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'clang/lib/Parse/ParseExprCXX.cpp') diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index d5f188104ed..229b76adde8 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -841,6 +841,7 @@ Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, // Parse capture. LambdaCaptureKind Kind = LCK_ByCopy; + LambdaCaptureInitKind InitKind = LambdaCaptureInitKind::NoInit; SourceLocation Loc; IdentifierInfo *Id = nullptr; SourceLocation EllipsisLoc; @@ -878,6 +879,8 @@ Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, BalancedDelimiterTracker Parens(*this, tok::l_paren); Parens.consumeOpen(); + InitKind = LambdaCaptureInitKind::DirectInit; + ExprVector Exprs; CommaLocsTy Commas; if (SkippedInits) { @@ -898,14 +901,13 @@ Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, // to save the necessary state, and restore it later. EnterExpressionEvaluationContext EC(Actions, Sema::PotentiallyEvaluated); - bool HadEquals = TryConsumeToken(tok::equal); + + if (TryConsumeToken(tok::equal)) + InitKind = LambdaCaptureInitKind::CopyInit; + else + InitKind = LambdaCaptureInitKind::ListInit; if (!SkippedInits) { - // Warn on constructs that will change meaning when we implement N3922 - if (!HadEquals && Tok.is(tok::l_brace)) { - Diag(Tok, diag::warn_init_capture_direct_list_init) - << FixItHint::CreateInsertion(Tok.getLocation(), "="); - } Init = ParseInitializer(); } else if (Tok.is(tok::l_brace)) { BalancedDelimiterTracker Braces(*this, tok::l_brace); @@ -993,19 +995,19 @@ Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, // If x was not const, the second use would require 'L' to capture, and // that would be an error. - ParsedType InitCaptureParsedType; + ParsedType InitCaptureType; if (Init.isUsable()) { // Get the pointer and store it in an lvalue, so we can use it as an // out argument. Expr *InitExpr = Init.get(); // This performs any lvalue-to-rvalue conversions if necessary, which // can affect what gets captured in the containing decl-context. - QualType InitCaptureType = Actions.performLambdaInitCaptureInitialization( - Loc, Kind == LCK_ByRef, Id, InitExpr); + InitCaptureType = Actions.actOnLambdaInitCaptureInitialization( + Loc, Kind == LCK_ByRef, Id, InitKind, InitExpr); Init = InitExpr; - InitCaptureParsedType.set(InitCaptureType); } - Intro.addCapture(Kind, Loc, Id, EllipsisLoc, Init, InitCaptureParsedType); + Intro.addCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init, + InitCaptureType); } T.consumeClose(); -- cgit v1.2.3