@@ -5597,61 +5597,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
55975597 Function->setLocation (PatternDecl->getLocation ());
55985598 Function->setInnerLocStart (PatternDecl->getInnerLocStart ());
55995599 Function->setRangeEnd (PatternDecl->getEndLoc ());
5600- // Let the instantiation use the Pattern's DeclarationNameLoc, due to the
5601- // following awkwardness:
5602- //
5603- // 1. There are out-of-tree users of getNameInfo().getSourceRange(), who
5604- // expect the source range of the instantiated declaration to be set to
5605- // point to the definition.
5606- //
5607- // 2. That getNameInfo().getSourceRange() might return the TypeLocInfo's
5608- // location it tracked.
5609- //
5610- // 3. Function might come from an (implicit) declaration, while the pattern
5611- // comes from a definition. In these cases, we need the PatternDecl's source
5612- // location.
5613- //
5614- // To that end, we need to more or less tweak the DeclarationNameLoc. However,
5615- // we can't blindly copy the DeclarationNameLoc from the PatternDecl to the
5616- // function, since it contains associated TypeLocs that should have already
5617- // been transformed. So, we rebuild the TypeLoc for that purpose. Technically,
5618- // we should create a new function declaration and assign everything we need,
5619- // but InstantiateFunctionDefinition updates the declaration in place.
5620- auto NameLocPointsToPattern = [&] {
5621- DeclarationNameInfo PatternName = PatternDecl->getNameInfo ();
5622- DeclarationNameLoc PatternNameLoc = PatternName.getInfo ();
5623- switch (PatternName.getName ().getNameKind ()) {
5624- case DeclarationName::CXXConstructorName:
5625- case DeclarationName::CXXDestructorName:
5626- case DeclarationName::CXXConversionFunctionName:
5627- break ;
5628- default :
5629- // Cases where DeclarationNameLoc doesn't matter, as it merely contains a
5630- // source range.
5631- return PatternNameLoc;
5632- }
5633-
5634- TypeSourceInfo *TSI = Function->getNameInfo ().getNamedTypeInfo ();
5635- // TSI might be null if the function is named by a constructor template id.
5636- // E.g. S<T>() {} for class template S with a template parameter T.
5637- if (!TSI) {
5638- // We don't care about the DeclarationName of the instantiated function,
5639- // but only the DeclarationNameLoc. So if the TypeLoc is absent, we do
5640- // nothing.
5641- return PatternNameLoc;
5642- }
5643-
5644- QualType InstT = TSI->getType ();
5645- // We want to use a TypeLoc that reflects the transformed type while
5646- // preserving the source location from the pattern.
5647- TypeLocBuilder TLB;
5648- TLB.pushTrivial (
5649- Context, InstT,
5650- PatternNameLoc.getNamedTypeInfo ()->getTypeLoc ().getBeginLoc ());
5651- return DeclarationNameLoc::makeNamedTypeLoc (
5652- TLB.getTypeSourceInfo (Context, InstT));
5653- };
5654- Function->setDeclarationNameLoc (NameLocPointsToPattern ());
5600+ Function->setDeclarationNameLoc (PatternDecl->getNameInfo ().getInfo ());
56555601
56565602 EnterExpressionEvaluationContext EvalContext (
56575603 *this , Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
0 commit comments