llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) <details> <summary>Changes</summary> Fixes https://github.com/llvm/llvm-project/issues/200682 --- Full diff: https://github.com/llvm/llvm-project/pull/208699.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.md (+1) - (modified) clang/lib/Parse/ParseDecl.cpp (+7-1) - (modified) clang/test/SemaTemplate/concepts-lambda.cpp (+37) ``````````diff 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> `````````` </details> https://github.com/llvm/llvm-project/pull/208699 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
