@@ -331,10 +331,15 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
331
331
332
332
// Declaration fragments of a pointer type is the declaration fragments of
333
333
// the pointee type followed by a `*`,
334
- if (T->isPointerType () && !T->isFunctionPointerType ())
335
- return Fragments
336
- .append (getFragmentsForType (T->getPointeeType (), Context, After))
337
- .append (" *" , DeclarationFragments::FragmentKind::Text);
334
+ if (T->isPointerType () && !T->isFunctionPointerType ()) {
335
+ QualType PointeeT = T->getPointeeType ();
336
+ Fragments.append (getFragmentsForType (PointeeT, Context, After));
337
+ // If the pointee is itself a pointer, we do not want to insert a space
338
+ // before the `*` as the preceding character in the type name is a `*`.
339
+ if (!PointeeT->isAnyPointerType ())
340
+ Fragments.appendSpace ();
341
+ return Fragments.append (" *" , DeclarationFragments::FragmentKind::Text);
342
+ }
338
343
339
344
// For Objective-C `id` and `Class` pointers
340
345
// we do not spell out the `*`.
@@ -638,7 +643,7 @@ DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
638
643
DeclarationFragments::FragmentKind::InternalParam);
639
644
} else {
640
645
Fragments.append (std::move (TypeFragments));
641
- if (!T->isBlockPointerType ())
646
+ if (!T->isAnyPointerType () && !T-> isBlockPointerType ())
642
647
Fragments.appendSpace ();
643
648
Fragments
644
649
.append (Param->getName (),
@@ -713,18 +718,20 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const FunctionDecl *Func) {
713
718
714
719
// FIXME: Is `after` actually needed here?
715
720
DeclarationFragments After;
721
+ QualType ReturnType = Func->getReturnType ();
716
722
auto ReturnValueFragment =
717
- getFragmentsForType (Func-> getReturnType () , Func->getASTContext (), After);
723
+ getFragmentsForType (ReturnType , Func->getASTContext (), After);
718
724
if (StringRef (ReturnValueFragment.begin ()->Spelling )
719
725
.starts_with (" type-parameter" )) {
720
- std::string ProperArgName = Func-> getReturnType () .getAsString ();
726
+ std::string ProperArgName = ReturnType .getAsString ();
721
727
ReturnValueFragment.begin ()->Spelling .swap (ProperArgName);
722
728
}
723
729
724
- Fragments.append (std::move (ReturnValueFragment))
725
- .appendSpace ()
726
- .append (Func->getNameAsString (),
727
- DeclarationFragments::FragmentKind::Identifier);
730
+ Fragments.append (std::move (ReturnValueFragment));
731
+ if (!ReturnType->isAnyPointerType ())
732
+ Fragments.appendSpace ();
733
+ Fragments.append (Func->getNameAsString (),
734
+ DeclarationFragments::FragmentKind::Identifier);
728
735
729
736
if (Func->getTemplateSpecializationInfo ()) {
730
737
Fragments.append (" <" , DeclarationFragments::FragmentKind::Text);
0 commit comments