From 8815f933ca95e1a69e127ccf0bb88e4fb5544548 Mon Sep 17 00:00:00 2001 From: dim Date: Mon, 29 Jan 2018 18:11:27 +0000 Subject: [PATCH] Pull in r217197 from upstream clang trunk (by Richard Smith): PR20844: If we fail to list-initialize a reference, map to the referenced type before retrying the initialization to produce diagnostics. Otherwise, we may fail to produce any diagnostics, and silently produce invalid AST in a -Asserts build. Also add a note to this codepath to make it more clear why we were trying to create a temporary. This should fix assertions when parsing some forms of incomplete list intializers. Direct commit to stable/9 and stable/10, since stable/11 and head already have this upstream fix. Reported by: ajcbowhill@gmail.com PR: 202665 git-svn-id: svn://svn.freebsd.org/base/stable/9@328555 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- .../include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ contrib/llvm/tools/clang/lib/Sema/SemaInit.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 6c7cb0018..0eb17e9c2 100644 --- a/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1419,6 +1419,9 @@ def warn_uninit_byref_blockvar_captured_by_block : Warning< InGroup, DefaultIgnore; def note_block_var_fixit_add_initialization : Note< "maybe you meant to use __block %0">; +def note_in_reference_temporary_list_initializer : Note< + "in initialization of temporary of type %0 created to " + "list-initialize this reference">; def note_var_fixit_add_initialization : Note< "initialize the variable %0 to silence this warning">; def note_uninit_fixit_remove_cond : Note< diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaInit.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaInit.cpp index 034c1b6c7..a680a191c 100644 --- a/contrib/llvm/tools/clang/lib/Sema/SemaInit.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/SemaInit.cpp @@ -6309,6 +6309,19 @@ static void diagnoseListInit(Sema &S, const InitializedEntity &Entity, return diagnoseListInit(S, HiddenArray, InitList); } + if (DestType->isReferenceType()) { + // A list-initialization failure for a reference means that we tried to + // create a temporary of the inner type (per [dcl.init.list]p3.6) and the + // inner initialization failed. + QualType T = DestType->getAs()->getPointeeType(); + diagnoseListInit(S, InitializedEntity::InitializeTemporary(T), InitList); + SourceLocation Loc = InitList->getLocStart(); + if (auto *D = Entity.getDecl()) + Loc = D->getLocation(); + S.Diag(Loc, diag::note_in_reference_temporary_list_initializer) << T; + return; + } + InitListChecker DiagnoseInitList(S, Entity, InitList, DestType, /*VerifyOnly=*/false); assert(DiagnoseInitList.HadError() && -- 2.45.0