https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/208699
Fixes https://github.com/llvm/llvm-project/issues/200682 >From ed21c0f84957f29062fa6d862e1f6a4a396c9d3f Mon Sep 17 00:00:00 2001 From: Younan Zhang <[email protected]> Date: Fri, 10 Jul 2026 19:27:42 +0800 Subject: [PATCH] [Clang] Ensure correct template parameter depth for abbreviated templates --- clang/docs/ReleaseNotes.md | 1 + clang/lib/Parse/ParseDecl.cpp | 8 ++++- clang/test/SemaTemplate/concepts-lambda.cpp | 37 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 4d7d9f2909096..886b11cc0148a 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -814,6 +814,7 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the - Fixed a preprocessor assertion failure triggered when parsing an invalid template-id starting with `::template operator`. (#GH186582) - Fixed a crash when a function template is defined as a non-template friend with a global scope qualifier. (#GH185341) +- Fixed a bug of incorrect template depth for abbreviated templates. (#GH200682) - Clang now rejects constant template parameters with block pointer types, since these are not implemented anyway and would lead to crashes. (#GH189247) - Clang no longer reject call expressions whose type is a not-yet-deduced auto type. (#GH207565) - Fixed a crash on error recovery when dealing with invalid templates. (#GH183075) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 3f41e7c5c6f0d..96aa99fb462c7 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2185,8 +2185,14 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, while (MaybeParseHLSLAnnotations(D)) ; - if (Tok.is(tok::kw_requires)) + if (Tok.is(tok::kw_requires)) { + TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); + // With abbreviated function templates - we need to explicitly add depth to + // account for the implicit template parameter list induced by the template. + if (!TemplateInfo.TemplateParams && D.getInventedTemplateParameterList()) + ++CurTemplateDepthTracker; ParseTrailingRequiresClauseWithScope(D); + } // Save late-parsed attributes for now; they need to be parsed in the // appropriate function scope after the function Decl has been constructed. diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp b/clang/test/SemaTemplate/concepts-lambda.cpp index 5a19105a5bf51..2349953736c4f 100644 --- a/clang/test/SemaTemplate/concepts-lambda.cpp +++ b/clang/test/SemaTemplate/concepts-lambda.cpp @@ -361,6 +361,43 @@ struct foo { constexpr auto bar = foo(seq<0>()); } +namespace GH200682 { + +template <typename... Args> struct A { + template <auto F> constexpr static bool B = F(42); +}; + +template <typename T> +concept c = true; + +template <typename T> +concept d = false; + +void f(auto &&...args) + requires( + A<decltype(args)...>::template B<[](auto x) { return c<decltype(x)>; }>); + +template <class> +void g(auto &&...args) + requires( + A<decltype(args)...>::template B<[](auto x) { return c<decltype(x)>; }>); + +void h(auto &&...args) // expected-note {{constraints not satisfied}} + requires( + A<decltype(args)...>::template B<[](auto x) { // expected-note {{evaluated to false}} + return d<decltype(x)>; + }>); + +void main() { + f(); + g<int>(); + + h(42); + // expected-error@-1 {{no matching}} +} + +} + namespace GH147650 { template <int> int b; template <int b> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
