From c7b2fde04d708279fcd9a82fd59eb84290a8955a Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Tue, 20 May 2025 13:48:28 +0800 Subject: [PATCH 1/2] Reapply "[Clang] Profile singly-resolved UnresolvedLookupExpr with the declaration" (#140655) This reverts commit 383e5f3e2da5c11ecbf1482eb0c39df38ac84e59. --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/StmtProfile.cpp | 5 ++++- .../SemaTemplate/concepts-out-of-line-def.cpp | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f04cb7b91788c..4c839303f3621 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -741,6 +741,7 @@ Bug Fixes to C++ Support - Fixed the handling of pack indexing types in the constraints of a member function redeclaration. (#GH138255) - Clang now correctly parses arbitrary order of ``[[]]``, ``__attribute__`` and ``alignas`` attributes for declarations (#GH133107) - Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852) +- Fixed a function declaration mismatch that caused inconsistencies between concepts and variable template declarations. (#GH139476) - Clang no longer segfaults when there is a configuration mismatch between modules and their users (http://crbug.com/400353616). - Fix an incorrect deduction when calling an explicit object member function template through an overload set address. - Fixed bug in constant evaluation that would allow using the value of a diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index f7d1655f67ed1..19db338f760ba 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -2189,7 +2189,10 @@ StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { VisitExpr(S); - VisitNestedNameSpecifier(S->getQualifier()); + if (S->getNumDecls() == 1) + VisitDecl(*S->decls_begin()); + else + VisitNestedNameSpecifier(S->getQualifier()); VisitName(S->getName(), /*TreatAsDecl*/ true); ID.AddBoolean(S->hasExplicitTemplateArgs()); if (S->hasExplicitTemplateArgs()) diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp index e5d00491d3fb8..bf505dec0ca14 100644 --- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp +++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp @@ -853,3 +853,18 @@ template requires C auto TplClass::buggy() -> void {} } + +namespace GH139476 { + +namespace moo { + template + constexpr bool baa = true; + + template requires baa + void caw(); +} + +template requires moo::baa +void moo::caw() {} + +} From a450de85c4a70dbe1bc168d5b7f0c5f603104fa7 Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Tue, 20 May 2025 13:48:50 +0800 Subject: [PATCH 2/2] Only profile Decls for dependent VarTemplates --- clang/lib/AST/StmtProfile.cpp | 9 ++++++--- clang/test/SemaCXX/exception-spec.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 19db338f760ba..2f1dec434c30b 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -2189,11 +2189,14 @@ StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { VisitExpr(S); - if (S->getNumDecls() == 1) + bool DescribingDependentVarTemplate = + S->getNumDecls() == 1 && isa(*S->decls_begin()); + if (DescribingDependentVarTemplate) { VisitDecl(*S->decls_begin()); - else + } else { VisitNestedNameSpecifier(S->getQualifier()); - VisitName(S->getName(), /*TreatAsDecl*/ true); + VisitName(S->getName(), /*TreatAsDecl*/ true); + } ID.AddBoolean(S->hasExplicitTemplateArgs()); if (S->hasExplicitTemplateArgs()) VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); diff --git a/clang/test/SemaCXX/exception-spec.cpp b/clang/test/SemaCXX/exception-spec.cpp index 6ad19aab397bd..31c691b28da4b 100644 --- a/clang/test/SemaCXX/exception-spec.cpp +++ b/clang/test/SemaCXX/exception-spec.cpp @@ -52,3 +52,24 @@ namespace AssignmentOp { D2 &operator=(const D2&); // expected-error {{more lax}} }; } + +namespace OverloadedFunctions { + +template +void f(T&) noexcept; + +template +void f(T (&arr)[N]) noexcept(noexcept(f(*arr))); + +template +inline void f(T&) noexcept {} + +template +inline void f(T (&arr)[N]) noexcept(noexcept(f(*arr))) {} + +void g() { + int x[1]; + f(x); +} + +}