When providing a completion for a function/method parameter of block
pointer type, actually provide a usable block literal expression.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113431 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index c367d52..d8c2c4f 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -1830,23 +1830,28 @@
   
   // We have the function prototype behind the block pointer type, as it was
   // written in the source.
-  std::string Result = "(^)(";
-  for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) {
-    if (I)
-      Result += ", ";
-    Result += FormatFunctionParameter(Context, Block->getArg(I));
-    
-    if (I == N - 1 && Block->getTypePtr()->isVariadic())
-      Result += ", ...";
+  std::string Result;
+  QualType ResultType = Block->getTypePtr()->getResultType();
+  if (!ResultType->isVoidType())
+    ResultType.getAsStringInternal(Result, Context.PrintingPolicy);
+  
+  Result = '^' + Result;
+  if (Block->getNumArgs() == 0) {
+    if (Block->getTypePtr()->isVariadic())
+      Result += "(...)";
+  } else {
+    Result += "(";
+    for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) {
+      if (I)
+        Result += ", ";
+      Result += FormatFunctionParameter(Context, Block->getArg(I));
+      
+      if (I == N - 1 && Block->getTypePtr()->isVariadic())
+        Result += ", ...";
+    }
+    Result += ")";
   }
-  if (Block->getTypePtr()->isVariadic() && Block->getNumArgs() == 0)
-    Result += "...";
-  else if (Block->getNumArgs() == 0 && !Context.getLangOptions().CPlusPlus)
-    Result += "void";
-             
-  Result += ")";
-  Block->getTypePtr()->getResultType().getAsStringInternal(Result, 
-                                                        Context.PrintingPolicy);
+  
   return Result;
 }