@@ -205,7 +205,8 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
205
205
LookupResult R (*this , TName, Name.getBeginLoc (), LookupOrdinaryName);
206
206
if (LookupTemplateName (R, S, SS, ObjectType, EnteringContext,
207
207
MemberOfUnknownSpecialization, SourceLocation (),
208
- &AssumedTemplate, Disambiguation))
208
+ &AssumedTemplate,
209
+ /* AllowTypoCorrection=*/ !Disambiguation))
209
210
return TNK_Non_template;
210
211
211
212
if (AssumedTemplate != AssumedTemplateKind::None) {
@@ -371,9 +372,9 @@ bool Sema::LookupTemplateName(LookupResult &Found,
371
372
QualType ObjectType,
372
373
bool EnteringContext,
373
374
bool &MemberOfUnknownSpecialization,
374
- SourceLocation TemplateKWLoc ,
375
+ RequiredTemplateKind RequiredTemplate ,
375
376
AssumedTemplateKind *ATK,
376
- bool Disambiguation ) {
377
+ bool AllowTypoCorrection ) {
377
378
if (ATK)
378
379
*ATK = AssumedTemplateKind::None;
379
380
@@ -473,7 +474,8 @@ bool Sema::LookupTemplateName(LookupResult &Found,
473
474
if (Found.isAmbiguous ())
474
475
return false ;
475
476
476
- if (ATK && SS.isEmpty () && ObjectType.isNull () && TemplateKWLoc.isInvalid ()) {
477
+ if (ATK && SS.isEmpty () && ObjectType.isNull () &&
478
+ !RequiredTemplate.hasTemplateKeyword ()) {
477
479
// C++2a [temp.names]p2:
478
480
// A name is also considered to refer to a template if it is an
479
481
// unqualified-id followed by a < and name lookup finds either one or more
@@ -499,7 +501,7 @@ bool Sema::LookupTemplateName(LookupResult &Found,
499
501
}
500
502
}
501
503
502
- if (Found.empty () && !IsDependent && !Disambiguation ) {
504
+ if (Found.empty () && !IsDependent && AllowTypoCorrection ) {
503
505
// If we did not find any names, and this is not a disambiguation, attempt
504
506
// to correct any typos.
505
507
DeclarationName Name = Found.getLookupName ();
@@ -545,9 +547,11 @@ bool Sema::LookupTemplateName(LookupResult &Found,
545
547
546
548
// If a 'template' keyword was used, a lookup that finds only non-template
547
549
// names is an error.
548
- if (ExampleLookupResult && TemplateKWLoc. isValid () ) {
550
+ if (ExampleLookupResult && RequiredTemplate ) {
549
551
Diag (Found.getNameLoc (), diag::err_template_kw_refers_to_non_template)
550
- << Found.getLookupName () << SS.getRange ();
552
+ << Found.getLookupName () << SS.getRange ()
553
+ << RequiredTemplate.hasTemplateKeyword ()
554
+ << RequiredTemplate.getTemplateKeywordLoc ();
551
555
Diag (ExampleLookupResult->getUnderlyingDecl ()->getLocation (),
552
556
diag::note_template_kw_refers_to_non_template)
553
557
<< Found.getLookupName ();
@@ -4722,10 +4726,14 @@ TemplateNameKind Sema::ActOnTemplateName(Scope *S,
4722
4726
LookupResult R (*this , DNI.getName (), Name.getBeginLoc (),
4723
4727
LookupOrdinaryName);
4724
4728
bool MOUS;
4725
- // FIXME: If LookupTemplateName fails here, we'll have produced its
4726
- // diagnostics twice.
4727
- if (!LookupTemplateName (R, S, SS, ObjectType.get (), EnteringContext,
4728
- MOUS, TemplateKWLoc) && !R.isAmbiguous ()) {
4729
+ // Tell LookupTemplateName that we require a template so that it diagnoses
4730
+ // cases where it finds a non-template.
4731
+ RequiredTemplateKind RTK = TemplateKWLoc.isValid ()
4732
+ ? RequiredTemplateKind (TemplateKWLoc)
4733
+ : TemplateNameIsRequired;
4734
+ if (!LookupTemplateName (R, S, SS, ObjectType.get (), EnteringContext, MOUS,
4735
+ RTK, nullptr , /* AllowTypoCorrection=*/ false ) &&
4736
+ !R.isAmbiguous ()) {
4729
4737
if (LookupCtx)
4730
4738
Diag (Name.getBeginLoc (), diag::err_no_member)
4731
4739
<< DNI.getName () << LookupCtx << SS.getRange ();
0 commit comments