diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 43a322030baae..1fbd332f74057 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -653,6 +653,9 @@ Bug Fixes in This Version - Fixed false positive error emitted by clang when performing qualified name lookup and the current class instantiation has dependent bases. Fixes (`#13826 `_) +- Fix a ``clang-17`` regression where a templated friend with constraints is not + properly applied when its parameters reference an enclosing non-template class. + Fixes (`#71595 `_) - Fix the name of the ifunc symbol emitted for multiversion functions declared with the ``target_clones`` attribute. This addresses a linker error that would otherwise occur when these functions are referenced from other TUs. diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 603ad2b79cecb..f10abeaba0d45 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1712,6 +1712,8 @@ class ConstraintRefersToContainingTemplateChecker // Friend, likely because it was referred to without its template arguments. void CheckIfContainingRecord(const CXXRecordDecl *CheckingRD) { CheckingRD = CheckingRD->getMostRecentDecl(); + if (!CheckingRD->isTemplated()) + return; for (const DeclContext *DC = Friend->getLexicalDeclContext(); DC && !DC->isFileContext(); DC = DC->getParent()) diff --git a/clang/test/SemaTemplate/GH71595.cpp b/clang/test/SemaTemplate/GH71595.cpp new file mode 100644 index 0000000000000..7d34d1bf054e4 --- /dev/null +++ b/clang/test/SemaTemplate/GH71595.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -std=c++20 -verify %s + +template +concept C = true; + +class non_temp { + template T> + friend void f(); + + non_temp(); +}; + +template T> +void f() { + auto v = non_temp(); +} + +template +class temp { + template T> + friend void g(); + + temp(); // expected-note {{implicitly declared private here}} +}; + +template> T> +void g() { + auto v = temp(); // expected-error {{calling a private constructor of class 'temp'}} +} + +void h() { + f(); + g(); // expected-note {{in instantiation of function template specialization 'g' requested here}} +}