From: Erik Pilkington Date: Mon, 23 Jul 2018 22:47:37 +0000 (+0000) Subject: [Sema] Fix crash on BlockExprs in a default member initializers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc6962eb2acb82e92637824fd3bb02b28619a195;p=clang [Sema] Fix crash on BlockExprs in a default member initializers Clang would crash when instantiating a BlockDecl that appeared in a default-member-initializer of a class template. Fix this by deferring the instantiation until we instantate the BlockExpr. rdar://41200624 Differential revision: https://reviews.llvm.org/D49688 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337766 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 5a4a6bd033..3cf584344c 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -2083,6 +2083,11 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, if (Member->getDeclContext() != Pattern) continue; + // BlockDecls can appear in a default-member-initializer. They must be the + // child of a BlockExpr, so we only know how to instantiate them from there. + if (isa(Member)) + continue; + if (Member->isInvalidDecl()) { Instantiation->setInvalidDecl(); continue; diff --git a/test/SemaCXX/instantiate-blocks.cpp b/test/SemaCXX/instantiate-blocks.cpp index bb0f8d881d..dbcef500b5 100644 --- a/test/SemaCXX/instantiate-blocks.cpp +++ b/test/SemaCXX/instantiate-blocks.cpp @@ -30,3 +30,12 @@ int main(void) noret((float)0.0, double(0.0)); // expected-note {{in instantiation of function template specialization 'noret' requested here}} } +namespace rdar41200624 { +template +struct S { + int (^p)() = ^{ return 0; }; + T (^t)() = ^{ return T{}; }; + T s = ^{ return T{}; }(); +}; +S x; +}