diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -1503,6 +1503,8 @@ struct MemberPointerTypeInfo { /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic. unsigned TypeQuals : 5; + /// Location of the '*' token. + unsigned StarLoc; // CXXScopeSpec has a constructor, so it can't be a direct member. // So we need some pointer-aligned storage and a bit of trickery. alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)]; @@ -1645,11 +1647,13 @@ static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, unsigned TypeQuals, - SourceLocation Loc) { + SourceLocation StarLoc, + SourceLocation EndLoc) { DeclaratorChunk I; I.Kind = MemberPointer; I.Loc = SS.getBeginLoc(); - I.EndLoc = Loc; + I.EndLoc = EndLoc; + I.Mem.StarLoc = StarLoc.getRawEncoding(); I.Mem.TypeQuals = TypeQuals; new (I.Mem.ScopeMem) CXXScopeSpec(SS); return I; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5552,6 +5552,7 @@ return; } + SourceLocation StarLoc = Tok.getLocation(); SourceLocation Loc = ConsumeToken(); D.SetRangeEnd(Loc); DeclSpec DS(AttrFactory); @@ -5564,7 +5565,7 @@ // Sema will have to catch (syntactically invalid) pointers into global // scope. It has to catch pointers into namespace scope anyway. D.AddTypeInfo(DeclaratorChunk::getMemberPointer( - SS, DS.getTypeQualifiers(), DS.getEndLoc()), + SS, DS.getTypeQualifiers(), StarLoc, DS.getEndLoc()), std::move(DS.getAttributes()), /* Don't replace range end. */ SourceLocation()); return; diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5691,7 +5691,7 @@ } // Finally fill in MemberPointerLocInfo fields. - TL.setStarLoc(Chunk.Loc); + TL.setStarLoc(SourceLocation::getFromRawEncoding(Chunk.Mem.StarLoc)); TL.setClassTInfo(ClsTInfo); } void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {