]> granicus.if.org Git - clang/commitdiff
Diagnose unexpanded parameter packs in return statements. This
authorDouglas Gregor <dgregor@apple.com>
Fri, 20 May 2011 15:32:55 +0000 (15:32 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 20 May 2011 15:32:55 +0000 (15:32 +0000)
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

lib/Sema/SemaStmt.cpp
lib/Sema/TreeTransform.h
test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp

index 536e86573b4fcccc458cbb21a824a1c3b7f37ebb..e541870ce8f815d8e1336e959e728a2df829fac9 100644 (file)
@@ -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);
 
index e007f062356a0b223f03286523a4525d830507f9..db65e2ba308c6b1eb501dfbb6d09f4fca1906573 100644 (file)
@@ -7803,20 +7803,21 @@ TreeTransform<Derived>::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<ParmVarDecl>(oldCapture) &&
+          cast<ParmVarDecl>(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<ParmVarDecl>(oldCapture) &&
-        cast<ParmVarDecl>(oldCapture)->isParameterPack())
-      continue;
-
-    VarDecl *newCapture =
-      cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
-                                               oldCapture));
-    assert(blockScope->CaptureMap.count(newCapture));
+      VarDecl *newCapture =
+        cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
+                                                 oldCapture));
+      assert(blockScope->CaptureMap.count(newCapture));
+    }
   }
 #endif
 
index 62cf4298f71759d2460148edd11cad8add8ca2cf..7375f98ec9c3288ca429e895fd50deb81a21804d 100644 (file)
@@ -37,3 +37,10 @@ int f3(Args ...args) {
 }
 
 template int f3(const char*, int, float, double);
+
+template<typename ...Args>
+int PR9953(Args ...args) {
+  return ^(Args *...block_args) {
+    return f1(block_args); // expected-error{{expression contains unexpanded parameter pack 'block_args'}}
+  }(&args...);
+}