Skip to content

Revert "[Clang] Fix dependent local class instantiation bugs" #135870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ Bug Fixes to C++ Support
by template argument deduction.
- Clang is now better at instantiating the function definition after its use inside
of a constexpr lambda. (#GH125747)
- Fixed a local class member function instantiation bug inside dependent lambdas. (#GH59734), (#GH132208)
- Clang no longer crashes when trying to unify the types of arrays with
certain differences in qualifiers (this could happen during template argument
deduction or when building a ternary operator). (#GH97005)
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,9 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
if (FunctionDecl *Pattern =
Function->getInstantiatedFromMemberFunction()) {

if (Function->isIneligibleOrNotSelected())
continue;

if (Function->getTrailingRequiresClause()) {
ConstraintSatisfaction Satisfaction;
if (CheckFunctionConstraints(Function, Satisfaction) ||
Expand Down
56 changes: 1 addition & 55 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5597,61 +5597,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
Function->setLocation(PatternDecl->getLocation());
Function->setInnerLocStart(PatternDecl->getInnerLocStart());
Function->setRangeEnd(PatternDecl->getEndLoc());
// Let the instantiation use the Pattern's DeclarationNameLoc, due to the
// following awkwardness:
//
// 1. There are out-of-tree users of getNameInfo().getSourceRange(), who
// expect the source range of the instantiated declaration to be set to
// point to the definition.
//
// 2. That getNameInfo().getSourceRange() might return the TypeLocInfo's
// location it tracked.
//
// 3. Function might come from an (implicit) declaration, while the pattern
// comes from a definition. In these cases, we need the PatternDecl's source
// location.
//
// To that end, we need to more or less tweak the DeclarationNameLoc. However,
// we can't blindly copy the DeclarationNameLoc from the PatternDecl to the
// function, since it contains associated TypeLocs that should have already
// been transformed. So, we rebuild the TypeLoc for that purpose. Technically,
// we should create a new function declaration and assign everything we need,
// but InstantiateFunctionDefinition updates the declaration in place.
auto NameLocPointsToPattern = [&] {
DeclarationNameInfo PatternName = PatternDecl->getNameInfo();
DeclarationNameLoc PatternNameLoc = PatternName.getInfo();
switch (PatternName.getName().getNameKind()) {
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
break;
default:
// Cases where DeclarationNameLoc doesn't matter, as it merely contains a
// source range.
return PatternNameLoc;
}

TypeSourceInfo *TSI = Function->getNameInfo().getNamedTypeInfo();
// TSI might be null if the function is named by a constructor template id.
// E.g. S<T>() {} for class template S with a template parameter T.
if (!TSI) {
// We don't care about the DeclarationName of the instantiated function,
// but only the DeclarationNameLoc. So if the TypeLoc is absent, we do
// nothing.
return PatternNameLoc;
}

QualType InstT = TSI->getType();
// We want to use a TypeLoc that reflects the transformed type while
// preserving the source location from the pattern.
TypeLocBuilder TLB;
TLB.pushTrivial(
Context, InstT,
PatternNameLoc.getNamedTypeInfo()->getTypeLoc().getBeginLoc());
return DeclarationNameLoc::makeNamedTypeLoc(
TLB.getTypeSourceInfo(Context, InstT));
};
Function->setDeclarationNameLoc(NameLocPointsToPattern());
Function->setDeclarationNameLoc(PatternDecl->getNameInfo().getInfo());

EnterExpressionEvaluationContext EvalContext(
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Expand Down
64 changes: 0 additions & 64 deletions clang/test/CodeGenCXX/local-class-instantiation.cpp

This file was deleted.

Loading