Skip to content

Commit 56aeb93

Browse files
committed
[FOLD] fix pre-c++23 compat
1 parent a22a02f commit 56aeb93

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
410410
LookupParsedName(Found, S, &SS, ObjectType,
411411
/*AllowBuiltinCreation=*/false, EnteringContext);
412412

413+
bool IsDependent = Found.wasNotFoundInCurrentInstantiation();
414+
413415
bool ObjectTypeSearchedInScope = false;
414416

415417
// C++ [basic.lookup.qual.general]p2:
@@ -428,8 +430,7 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
428430
// we perform the unqualified lookup in the template definition context
429431
// and store the results so we can replicate the lookup during instantiation.
430432
if (MayBeNNS && Found.empty() && !ObjectType.isNull() &&
431-
(!getLangOpts().CPlusPlus23 ||
432-
!Found.wasNotFoundInCurrentInstantiation())) {
433+
(!getLangOpts().CPlusPlus23 || !IsDependent)) {
433434
if (S) {
434435
LookupName(Found, S);
435436
} else if (!SS.getUnqualifiedLookups().empty()) {
@@ -503,7 +504,7 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
503504
}
504505
}
505506

506-
if (Found.empty() && AllowTypoCorrection) {
507+
if (Found.empty() && AllowTypoCorrection && !IsDependent) {
507508
// If we did not find any names, and this is not a disambiguation, attempt
508509
// to correct any typos.
509510
DeclarationName Name = Found.getLookupName();
@@ -544,14 +545,14 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
544545

545546
NamedDecl *ExampleLookupResult =
546547
Found.empty() ? nullptr : Found.getRepresentativeDecl();
547-
FilterAcceptableTemplateNames(
548-
Found,
549-
/*AllowFunctionTemplates=*/getLangOpts().CPlusPlus23 ||
550-
!ObjectTypeSearchedInScope);
548+
FilterAcceptableTemplateNames(Found, getLangOpts().CPlusPlus23 ||
549+
!ObjectTypeSearchedInScope);
551550
if (Found.empty()) {
552-
// If a 'template' keyword was used, a lookup that finds only non-template
553-
// names is an error.
554-
if (ExampleLookupResult && RequiredTemplate) {
551+
if (IsDependent) {
552+
Found.setNotFoundInCurrentInstantiation();
553+
} else if (ExampleLookupResult && RequiredTemplate) {
554+
// If a 'template' keyword was used, a lookup that finds only non-template
555+
// names is an error.
555556
Diag(Found.getNameLoc(), diag::err_template_kw_refers_to_non_template)
556557
<< Found.getLookupName() << SS.getRange()
557558
<< RequiredTemplate.hasTemplateKeyword()

clang/test/CXX/drs/cwg13xx.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98-20,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2-
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-20,cxx11-17,cxx11-14,cxx98-14,cxx98-20,since-cxx11,cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3-
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx11-20,cxx11-17,cxx11-14,since-cxx14,cxx98-14,cxx98-20,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4-
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx11-20,cxx11-17,cxx98-20,since-cxx14,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5-
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,cxx11-20,cxx98-20,since-cxx14,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
1+
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2+
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-20,cxx11-17,cxx11-14,cxx98-14,since-cxx11,cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx11-20,cxx11-17,cxx11-14,since-cxx14,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx11-20,cxx11-17,since-cxx14,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,cxx11-20,since-cxx14,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
66
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
77
// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
88

@@ -136,7 +136,6 @@ namespace cwg1310 { // cwg1310: 5
136136
// expected-error@-1 {{ISO C++ specifies that qualified reference to 'W' is a constructor name rather than a template name in this context, despite preceding 'template' keyword}}
137137
}
138138
template<typename W>
139-
// cxx98-20-note@-1 2{{declared as a non-template here}}
140139
void wt_test_good() {
141140
typename W::W::X w2ax;
142141
typename W::template W<int>::X w4x;
@@ -147,9 +146,7 @@ namespace cwg1310 { // cwg1310: 5
147146
(void)w.W::W::n;
148147
(void)w.W::template W<int>::n;
149148
(void)w.template W<int>::W::n;
150-
// cxx98-20-error@-1 {{'W' following the 'template' keyword does not refer to a template}}
151149
(void)w.template W<int>::template W<int>::n;
152-
// cxx98-20-error@-1 {{'W' following the 'template' keyword does not refer to a template}}
153150
}
154151
template void wt_test<W<int> >(); // #cwg1310-W-int
155152
template void wt_test_good<W<int> >();

0 commit comments

Comments
 (0)