release/23.x: [Clang] Ensure correct template parameter depth for abbreviated templates (#209693) - #209712
Merged
Merged
Conversation
Member
Author
|
@cor3ntin What do you think about merging this PR to the release branch? |
|
@llvm/pr-subscribers-clang Author: llvmbot ChangesBackport 3485d85 Requested by: @zyn0217 Full diff: https://github.com/llvm/llvm-project/pull/209712.diff 2 Files Affected:
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 893989bd2398f..d7a9c72eb2da8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2534,6 +2534,12 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
if (BitfieldSize.isInvalid())
SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch);
} else 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 (DeclaratorInfo.getTemplateParameterLists().empty() &&
+ DeclaratorInfo.getInventedTemplateParameterList())
+ ++CurTemplateDepthTracker;
ParseTrailingRequiresClauseWithScope(DeclaratorInfo);
} else {
ParseOptionalCXX11VirtSpecifierSeq(
diff --git a/clang/test/SemaCXX/constexpr-late-instantiation.cpp b/clang/test/SemaCXX/constexpr-late-instantiation.cpp
index 9aec0c90e61dc..94f5ab4a73616 100644
--- a/clang/test/SemaCXX/constexpr-late-instantiation.cpp
+++ b/clang/test/SemaCXX/constexpr-late-instantiation.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify
-// RUN: %clang_cc1 %s -fexperimental-new-constant-interpreter -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++14 -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify
+
+// RUN: %clang_cc1 %s -std=c++14 -fsyntax-only -fexperimental-new-constant-interpreter -verify
+// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -fexperimental-new-constant-interpreter -verify
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -fexperimental-new-constant-interpreter -verify
template <typename T>
constexpr T foo(T a); // expected-note {{declared here}}
@@ -14,3 +19,28 @@ template <typename T>
constexpr T foo(T a) {
return a;
}
+
+#if __cplusplus > 202002L
+
+namespace GH115118 {
+
+struct foo {
+ // expected-note@-1 2{{while}}
+ foo(const foo&) = default;
+ foo(auto)
+ requires([]<int = 0>() -> bool { return true; }())
+ // expected-error@-1 {{non-constant expression}}
+ // expected-note@-2 {{undefined function}} \
+ // expected-note@-2 {{declared}}
+ {}
+};
+
+// FIXME: This will be fixed by https://github.com/llvm/llvm-project/pull/205557
+struct bar {
+ // expected-note@-1 {{while}}
+ foo x; // check that the lambda gets instantiated.
+};
+
+} // namespace GH115118
+
+#endif
|
Contributor
cor3ntin
approved these changes
Jul 21, 2026
cor3ntin
left a comment
Contributor
There was a problem hiding this comment.
LGTM - but we probably want a release note
Contributor
We don't have to, that assertion was introduced in clang 23 |
…ates (llvm#209693) This fixes another case of member functions where we overlooked template depths when only abbreviated template parameters are involved. This mirrors previous fix cfb2520, but I don't intend to put it in ParseTrailingRequiresClause because we might want the similar fix for e.g. noexcept expressions, so let's keep it inline for future refactor. The example comes from llvm#205557. (cherry picked from commit 3485d85)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 3485d85
Requested by: @zyn0217