@@ -405,36 +405,6 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
405405 LookupParsedName (Found, S, &SS, ObjectType,
406406 /* AllowBuiltinCreation=*/ false , EnteringContext);
407407
408- bool IsDependent = Found.wasNotFoundInCurrentInstantiation ();
409-
410- bool ObjectTypeSearchedInScope = false ;
411-
412- // C++ [basic.lookup.qual.general]p2:
413- // A member-qualified name is the (unique) component name, if any, of
414- // - an unqualified-id or
415- // - a nested-name-specifier of the form type-name :: or namespace-name ::
416- // in the id-expression of a class member access expression.
417- //
418- // C++ [basic.lookup.qual.general]p3:
419- // [...] If nothing is found by qualified lookup for a member-qualified
420- // name that is the terminal name of a nested-name-specifier and is not
421- // dependent, it undergoes unqualified lookup.
422- //
423- // In 'x.A::B::y', 'A' will undergo unqualified lookup if qualified lookup
424- // in the type of 'x' finds nothing. If the lookup context is dependent,
425- // we perform the unqualified lookup in the template definition context
426- // and store the results so we can replicate the lookup during instantiation.
427- if (MayBeNNS && Found.empty () && !ObjectType.isNull () &&
428- (!getLangOpts ().CPlusPlus23 || !IsDependent)) {
429- if (S) {
430- LookupName (Found, S);
431- } else if (!SS.getUnqualifiedLookups ().empty ()) {
432- Found.addAllDecls (SS.getUnqualifiedLookups ());
433- Found.resolveKind ();
434- }
435- ObjectTypeSearchedInScope = true ;
436- }
437-
438408 // C++ [basic.lookup.qual.general]p3:
439409 // [...] Unless otherwise specified, a qualified name undergoes qualified
440410 // name lookup in its lookup context from the point where it appears unless
@@ -470,6 +440,33 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
470440 if (Found.wasNotFoundInCurrentInstantiation ())
471441 return false ;
472442
443+ bool ObjectTypeSearchedInScope = false ;
444+
445+ // C++ [basic.lookup.qual.general]p2:
446+ // A member-qualified name is the (unique) component name, if any, of
447+ // - an unqualified-id or
448+ // - a nested-name-specifier of the form type-name :: or namespace-name ::
449+ // in the id-expression of a class member access expression.
450+ //
451+ // C++ [basic.lookup.qual.general]p3:
452+ // [...] If nothing is found by qualified lookup for a member-qualified
453+ // name that is the terminal name of a nested-name-specifier and is not
454+ // dependent, it undergoes unqualified lookup.
455+ //
456+ // In 'x.A::B::y', 'A' will undergo unqualified lookup if qualified lookup
457+ // in the type of 'x' finds nothing. If the lookup context is dependent,
458+ // we perform the unqualified lookup in the template definition context
459+ // and store the results so we can replicate the lookup during instantiation.
460+ if (MayBeNNS && Found.empty () && !ObjectType.isNull ()) {
461+ if (S) {
462+ LookupName (Found, S);
463+ } else if (!SS.getUnqualifiedLookups ().empty ()) {
464+ Found.addAllDecls (SS.getUnqualifiedLookups ());
465+ Found.resolveKind ();
466+ }
467+ ObjectTypeSearchedInScope = true ;
468+ }
469+
473470 if (Found.isAmbiguous ())
474471 return false ;
475472
@@ -499,7 +496,7 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
499496 }
500497 }
501498
502- if (Found.empty () && AllowTypoCorrection && !IsDependent ) {
499+ if (Found.empty () && AllowTypoCorrection) {
503500 // If we did not find any names, and this is not a disambiguation, attempt
504501 // to correct any typos.
505502 DeclarationName Name = Found.getLookupName ();
@@ -540,12 +537,9 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
540537
541538 NamedDecl *ExampleLookupResult =
542539 Found.empty () ? nullptr : Found.getRepresentativeDecl ();
543- FilterAcceptableTemplateNames (Found, getLangOpts ().CPlusPlus23 ||
544- !ObjectTypeSearchedInScope);
540+ FilterAcceptableTemplateNames (Found);
545541 if (Found.empty ()) {
546- if (IsDependent) {
547- Found.setNotFoundInCurrentInstantiation ();
548- } else if (ExampleLookupResult && RequiredTemplate) {
542+ if (ExampleLookupResult && RequiredTemplate) {
549543 // If a 'template' keyword was used, a lookup that finds only non-template
550544 // names is an error.
551545 Diag (Found.getNameLoc (), diag::err_template_kw_refers_to_non_template)
0 commit comments