diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-11-11 01:36:17 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-11-11 01:36:17 +0000 |
commit | 42b10572443e3f3f3c4a113f88ad4e9b504df900 (patch) | |
tree | b826b89beb307ed24b6ffedf840c5605ccabb3f4 /clang/lib/Parse/ParseExprCXX.cpp | |
parent | 754cd11d9019e62a4c6a0aee62159e707f6f51d9 (diff) | |
download | bcm5719-llvm-42b10572443e3f3f3c4a113f88ad4e9b504df900.tar.gz bcm5719-llvm-42b10572443e3f3f3c4a113f88ad4e9b504df900.zip |
N3922: direct-list-initialization of an auto-typed variable no longer deduces a
std::initializer_list<T> 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
Diffstat (limited to 'clang/lib/Parse/ParseExprCXX.cpp')
-rw-r--r-- | clang/lib/Parse/ParseExprCXX.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
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<unsigned> 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<unsigned> 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<unsigned> 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<unsigned> 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(); |