@@ -324,10 +324,15 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
324
324
325
325
// Declaration fragments of a pointer type is the declaration fragments of
326
326
// 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
+ }
331
336
332
337
// For Objective-C `id` and `Class` pointers
333
338
// we do not spell out the `*`.
@@ -631,7 +636,7 @@ DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
631
636
DeclarationFragments::FragmentKind::InternalParam);
632
637
} else {
633
638
Fragments.append (std::move (TypeFragments));
634
- if (!T->isBlockPointerType ())
639
+ if (!T->isAnyPointerType () && !T-> isBlockPointerType ())
635
640
Fragments.appendSpace ();
636
641
Fragments
637
642
.append (Param->getName (),
@@ -706,18 +711,20 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const FunctionDecl *Func) {
706
711
707
712
// FIXME: Is `after` actually needed here?
708
713
DeclarationFragments After;
714
+ QualType ReturnType = Func->getReturnType ();
709
715
auto ReturnValueFragment =
710
- getFragmentsForType (Func-> getReturnType () , Func->getASTContext (), After);
716
+ getFragmentsForType (ReturnType , Func->getASTContext (), After);
711
717
if (StringRef (ReturnValueFragment.begin ()->Spelling )
712
718
.starts_with (" type-parameter" )) {
713
- std::string ProperArgName = Func-> getReturnType () .getAsString ();
719
+ std::string ProperArgName = ReturnType .getAsString ();
714
720
ReturnValueFragment.begin ()->Spelling .swap (ProperArgName);
715
721
}
716
722
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);
721
728
722
729
if (Func->getTemplateSpecializationInfo ()) {
723
730
Fragments.append (" <" , DeclarationFragments::FragmentKind::Text);
0 commit comments