]> granicus.if.org Git - clang/commitdiff
Complain if block-literal expression's parameter name is
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Feb 2010 21:53:14 +0000 (21:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Feb 2010 21:53:14 +0000 (21:53 +0000)
missing (in c/objc mode). Fixes radar 7528255.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96017 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp
test/Sema/block-args.c

index feb9f8511cd6a524f921db7d84daab93bd2e1b76..1fc08ce03197e66a68063e5a60f704987356e0ba 100644 (file)
@@ -3875,6 +3875,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
         // Recover by removing the name
         II = 0;
         D.SetIdentifier(0, D.getIdentifierLoc());
+        D.setInvalidType(true);
       }
     }
   }
index 940c3d3e7ffaae58a3c9c7b45f14d1bc51febdde..633884f673ba5f7ac7a0936875b79bd267993a47 100644 (file)
@@ -6830,8 +6830,15 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
     // empty arg list, don't push any params.
     CurBlock->isVariadic = false;
   } else if (FTI.hasPrototype) {
-    for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
-      CurBlock->Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
+    for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
+      ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>();
+      if (Param->getIdentifier() == 0 &&
+          !Param->isImplicit() &&
+          !Param->isInvalidDecl() &&
+          !getLangOptions().CPlusPlus)
+        Diag(Param->getLocation(), diag::err_parameter_name_omitted);
+      CurBlock->Params.push_back(Param);
+    }
     CurBlock->isVariadic = FTI.isVariadic;
   }
   CurBlock->TheDecl->setParams(CurBlock->Params.data(),
index 08af9b377361ff0669dce7a5f3ba1d22ce5993ac..a07c82e75afa902253edf3e7b769009cfc183580 100644 (file)
@@ -27,3 +27,9 @@ int main(int argc, char** argv) {
     argCount = 3;
   }(argc);
 }
+
+// radar 7528255
+void f0() {
+  ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
+                                          // expected-error {{parameter name omitted}}
+}