Skip to content

Commit 228e04f

Browse files
committed
[FOLD]
1 parent 4cbba64 commit 228e04f

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9138,6 +9138,12 @@ class Sema final {
91389138
bool EnteringContext, bool &MemberOfUnknownSpecialization,
91399139
RequiredTemplateKind RequiredTemplate = SourceLocation(),
91409140
AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true);
9141+
9142+
bool LookupTemplateName(
9143+
LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType,
9144+
bool EnteringContext,
9145+
RequiredTemplateKind RequiredTemplate = SourceLocation(),
9146+
AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true);
91419147

91429148
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS,
91439149
bool hasTemplateKeyword,

clang/lib/Sema/SemaLookup.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,19 +2722,19 @@ bool Sema::LookupParsedName(LookupResult &R,
27222722
QualType ObjectType,
27232723
bool AllowBuiltinCreation,
27242724
bool EnteringContext) {
2725-
if (SS && SS->isInvalid()) {
2726-
// When the scope specifier is invalid, don't even look for
2727-
// anything.
2725+
// When the scope specifier is invalid, don't even look for anything.
2726+
if (SS && SS->isInvalid())
27282727
return false;
2729-
}
27302728

27312729
// Determine where to perform name lookup
27322730
DeclContext *DC = nullptr;
2731+
bool IsDependent = false;
27332732
if (!ObjectType.isNull()) {
27342733
// This nested-name-specifier occurs in a member access expression, e.g.,
27352734
// x->B::f, and we are looking into the type of the object.
27362735
assert((!SS || SS->isEmpty()) && "ObjectType and scope specifier cannot coexist");
27372736
DC = computeDeclContext(ObjectType);
2737+
IsDependent = !DC && ObjectType->isDependentType();
27382738
assert(((!DC && ObjectType->isDependentType()) ||
27392739
!ObjectType->isIncompleteType() ||
27402740
!ObjectType->getAs<TagType>() ||
@@ -2752,6 +2752,7 @@ bool Sema::LookupParsedName(LookupResult &R,
27522752
return false;
27532753
R.setContextRange(SS->getRange());
27542754
}
2755+
IsDependent = !DC && isDependentScopeSpecifier(*SS);
27552756
} else {
27562757
// Perform unqualified name lookup starting in the given scope.
27572758
return LookupName(R, S, AllowBuiltinCreation);
@@ -2761,11 +2762,11 @@ bool Sema::LookupParsedName(LookupResult &R,
27612762
// lookup in that context.
27622763
if (DC)
27632764
return LookupQualifiedName(R, DC);
2764-
2765-
// We could not resolve the scope specified to a specific declaration
2766-
// context, which means that SS refers to an unknown specialization.
2767-
// Name lookup can't find anything in this case.
2768-
R.setNotFoundInCurrentInstantiation();
2765+
else if (IsDependent)
2766+
// We could not resolve the scope specified to a specific declaration
2767+
// context, which means that SS refers to an unknown specialization.
2768+
// Name lookup can't find anything in this case.
2769+
R.setNotFoundInCurrentInstantiation();
27692770
return false;
27702771
}
27712772

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,12 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
319319
bool Sema::isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
320320
SourceLocation NameLoc, CXXScopeSpec &SS,
321321
ParsedTemplateTy *Template /*=nullptr*/) {
322-
bool MemberOfUnknownSpecialization = false;
323-
324322
// We could use redeclaration lookup here, but we don't need to: the
325323
// syntactic form of a deduction guide is enough to identify it even
326324
// if we can't look up the template name at all.
327325
LookupResult R(*this, DeclarationName(&Name), NameLoc, LookupOrdinaryName);
328326
if (LookupTemplateName(R, S, SS, /*ObjectType*/ QualType(),
329-
/*EnteringContext*/ false,
330-
MemberOfUnknownSpecialization))
327+
/*EnteringContext*/ false))
331328
return false;
332329

333330
if (R.empty()) return false;
@@ -373,6 +370,19 @@ bool Sema::DiagnoseUnknownTemplateName(const IdentifierInfo &II,
373370
return true;
374371
}
375372

373+
bool Sema::LookupTemplateName(LookupResult &Found,
374+
Scope *S, CXXScopeSpec &SS,
375+
QualType ObjectType,
376+
bool EnteringContext,
377+
RequiredTemplateKind RequiredTemplate,
378+
AssumedTemplateKind *ATK,
379+
bool AllowTypoCorrection) {
380+
bool MemberOfUnknownSpecialization;
381+
return LookupTemplateName(Found, S, SS, ObjectType, EnteringContext,
382+
MemberOfUnknownSpecialization, RequiredTemplate,
383+
ATK, AllowTypoCorrection);
384+
}
385+
376386
bool Sema::LookupTemplateName(LookupResult &Found,
377387
Scope *S, CXXScopeSpec &SS,
378388
QualType ObjectType,
@@ -5447,10 +5457,9 @@ Sema::BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
54475457
RequireCompleteDeclContext(SS, DC))
54485458
return BuildDependentDeclRefExpr(SS, TemplateKWLoc, NameInfo, TemplateArgs);
54495459

5450-
bool MemberOfUnknownSpecialization;
54515460
LookupResult R(*this, NameInfo, LookupOrdinaryName);
54525461
if (LookupTemplateName(R, (Scope *)nullptr, SS, QualType(),
5453-
/*Entering*/false, MemberOfUnknownSpecialization,
5462+
/*Entering*/false,
54545463
TemplateKWLoc))
54555464
return ExprError();
54565465

@@ -5572,14 +5581,13 @@ TemplateNameKind Sema::ActOnTemplateName(Scope *S,
55725581
DeclarationNameInfo DNI = GetNameFromUnqualifiedId(Name);
55735582
LookupResult R(*this, DNI.getName(), Name.getBeginLoc(),
55745583
LookupOrdinaryName);
5575-
bool MOUS;
55765584
// Tell LookupTemplateName that we require a template so that it diagnoses
55775585
// cases where it finds a non-template.
55785586
RequiredTemplateKind RTK = TemplateKWLoc.isValid()
55795587
? RequiredTemplateKind(TemplateKWLoc)
55805588
: TemplateNameIsRequired;
5581-
if (!LookupTemplateName(R, S, SS, ObjectType.get(), EnteringContext, MOUS,
5582-
RTK, nullptr, /*AllowTypoCorrection=*/false) &&
5589+
if (!LookupTemplateName(R, S, SS, ObjectType.get(), EnteringContext,
5590+
RTK, /*ATK=*/nullptr, /*AllowTypoCorrection=*/false) &&
55835591
!R.isAmbiguous()) {
55845592
if (LookupCtx)
55855593
Diag(Name.getBeginLoc(), diag::err_no_member)

0 commit comments

Comments
 (0)