-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Clang] Add the template depth when parsing type constraints #163960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The lambdas can introduce new template parameters, and things would go wrong if the new template parameters still lived in the depth of the parent, when we evaluate the type constraints.
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesThe lambdas can introduce new template parameters, and things would go wrong if the new template parameters still lived in the depth of the parent, when we evaluate the type constraints. Fixes #162092 Full diff: https://github.com/llvm/llvm-project/pull/163960.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db2b0f6fd5027..2f0c9f66e2501 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -469,6 +469,7 @@ Bug Fixes to C++ Support
- Fix a crash when attempting to deduce a deduction guide from a non deducible template template parameter. (#130604)
- Fix for clang incorrectly rejecting the default construction of a union with
nontrivial member when another member has an initializer. (#GH81774)
+- Fixed a template depth issue when parsing lambdas inside a type constraint. (#GH162092)
- Diagnose unresolved overload sets in non-dependent compound requirements. (#GH51246) (#GH97753)
Bug Fixes to AST Handling
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index dbc7cbc6cdc0c..445bee98bf646 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -533,6 +533,12 @@ bool Parser::isTypeConstraintAnnotation() {
bool Parser::TryAnnotateTypeConstraint() {
if (!getLangOpts().CPlusPlus20)
return false;
+ // The type constraint may declare template parameters, notably
+ // if it contains a generic lambda, so we need to increase
+ // the template depth as these parameters would not be instantiated
+ // at the current level.
+ TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
+ ++CurTemplateDepthTracker;
CXXScopeSpec SS;
bool WasScopeAnnotation = Tok.is(tok::annot_cxxscope);
if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp
index 3fbe7c0ac650f..4dad17f0a6e46 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1489,6 +1489,31 @@ static_assert( requires {{ &f } -> C;} ); // expected-error {{reference to overl
}
+namespace GH162092 {
+
+template <typename T>
+struct vector;
+
+template <typename T, typename U>
+concept C = __is_same_as(T, U);
+
+template<class T, auto Cpt>
+concept generic_range_value = requires {
+ Cpt.template operator()<int>();
+};
+
+
+template<generic_range_value<[]<
+ C<int>
+ >() {}> T>
+void x() {}
+
+void foo() {
+ x<vector<int>>();
+}
+
+}
+
namespace GH162770 {
enum e {};
template<e> struct s {};
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/161/builds/8490 Here is the relevant piece of the build log for the reference
|
The lambdas can introduce new template parameters, and things would go wrong if the new template parameters still lived in the depth of the parent, when we evaluate the type constraints.
Fixes #162092