From: Douglas Gregor Date: Fri, 20 May 2011 15:32:55 +0000 (+0000) Subject: Diagnose unexpanded parameter packs in return statements. This X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc92137eee708b632c00a9b0934ff87aeae234a5;p=clang Diagnose unexpanded parameter packs in return statements. This manifested in a crash with blocks in PR9953, but it was a ticking time bomb for normal functions, too. Fixes PR9953. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131731 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 536e86573b..e541870ce8 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1665,6 +1665,10 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { StmtResult Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { + // Check for unexpanded parameter packs. + if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp)) + return StmtError(); + if (getCurBlock()) return ActOnBlockReturnStmt(ReturnLoc, RetValExp); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index e007f06235..db65e2ba30 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -7803,20 +7803,21 @@ TreeTransform::TransformBlockExpr(BlockExpr *E) { #ifndef NDEBUG // In builds with assertions, make sure that we captured everything we // captured before. + if (!SemaRef.getDiagnostics().hasErrorOccurred()) { + for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), + e = oldBlock->capture_end(); i != e; ++i) { + VarDecl *oldCapture = i->getVariable(); + + // Ignore parameter packs. + if (isa(oldCapture) && + cast(oldCapture)->isParameterPack()) + continue; - for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), - e = oldBlock->capture_end(); i != e; ++i) { - VarDecl *oldCapture = i->getVariable(); - - // Ignore parameter packs. - if (isa(oldCapture) && - cast(oldCapture)->isParameterPack()) - continue; - - VarDecl *newCapture = - cast(getDerived().TransformDecl(E->getCaretLocation(), - oldCapture)); - assert(blockScope->CaptureMap.count(newCapture)); + VarDecl *newCapture = + cast(getDerived().TransformDecl(E->getCaretLocation(), + oldCapture)); + assert(blockScope->CaptureMap.count(newCapture)); + } } #endif diff --git a/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp b/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp index 62cf4298f7..7375f98ec9 100644 --- a/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp +++ b/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp @@ -37,3 +37,10 @@ int f3(Args ...args) { } template int f3(const char*, int, float, double); + +template +int PR9953(Args ...args) { + return ^(Args *...block_args) { + return f1(block_args); // expected-error{{expression contains unexpanded parameter pack 'block_args'}} + }(&args...); +}