@@ -324,10 +324,15 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
324324
325325 // Declaration fragments of a pointer type is the declaration fragments of
326326 // the pointee type followed by a `*`,
327- if (T->isPointerType () && !T->isFunctionPointerType ())
328- return Fragments
329- .append (getFragmentsForType (T->getPointeeType (), Context, After))
330- .append (" *" , DeclarationFragments::FragmentKind::Text);
327+ if (T->isPointerType () && !T->isFunctionPointerType ()) {
328+ QualType PointeeT = T->getPointeeType ();
329+ Fragments.append (getFragmentsForType (PointeeT, Context, After));
330+ // If the pointee is itself a pointer, we do not want to insert a space
331+ // before the `*` as the preceding character in the type name is a `*`.
332+ if (!PointeeT->isAnyPointerType ())
333+ Fragments.appendSpace ();
334+ return Fragments.append (" *" , DeclarationFragments::FragmentKind::Text);
335+ }
331336
332337 // For Objective-C `id` and `Class` pointers
333338 // we do not spell out the `*`.
@@ -631,7 +636,7 @@ DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
631636 DeclarationFragments::FragmentKind::InternalParam);
632637 } else {
633638 Fragments.append (std::move (TypeFragments));
634- if (!T->isBlockPointerType ())
639+ if (!T->isAnyPointerType () && !T-> isBlockPointerType ())
635640 Fragments.appendSpace ();
636641 Fragments
637642 .append (Param->getName (),
@@ -706,18 +711,20 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const FunctionDecl *Func) {
706711
707712 // FIXME: Is `after` actually needed here?
708713 DeclarationFragments After;
714+ QualType ReturnType = Func->getReturnType ();
709715 auto ReturnValueFragment =
710- getFragmentsForType (Func-> getReturnType () , Func->getASTContext (), After);
716+ getFragmentsForType (ReturnType , Func->getASTContext (), After);
711717 if (StringRef (ReturnValueFragment.begin ()->Spelling )
712718 .starts_with (" type-parameter" )) {
713- std::string ProperArgName = Func-> getReturnType () .getAsString ();
719+ std::string ProperArgName = ReturnType .getAsString ();
714720 ReturnValueFragment.begin ()->Spelling .swap (ProperArgName);
715721 }
716722
717- Fragments.append (std::move (ReturnValueFragment))
718- .appendSpace ()
719- .append (Func->getNameAsString (),
720- DeclarationFragments::FragmentKind::Identifier);
723+ Fragments.append (std::move (ReturnValueFragment));
724+ if (!ReturnType->isAnyPointerType ())
725+ Fragments.appendSpace ();
726+ Fragments.append (Func->getNameAsString (),
727+ DeclarationFragments::FragmentKind::Identifier);
721728
722729 if (Func->getTemplateSpecializationInfo ()) {
723730 Fragments.append (" <" , DeclarationFragments::FragmentKind::Text);
0 commit comments