[llvm-branch-commits] [clang] release/23.x: [Clang] Ensure correct template parameter depth for abbreviated templates (#209693) (PR #209712)
Douglas Yung via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 22 06:44:55 PDT 2026
https://github.com/dyung updated https://github.com/llvm/llvm-project/pull/209712
>From 5deccad3415aacaec099795cd1d57dfd84b767e0 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Wed, 15 Jul 2026 17:42:50 +0800
Subject: [PATCH] [Clang] Ensure correct template parameter depth for
abbreviated templates (#209693)
This fixes another case of member functions where we overlooked template
depths when only abbreviated template parameters are involved.
This mirrors previous fix cfb25203c25f, 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 #205557.
(cherry picked from commit 3485d8591992a967553493c53f17d9f3e8a0fc8e)
---
clang/lib/Parse/ParseDeclCXX.cpp | 6 ++++
.../SemaCXX/constexpr-late-instantiation.cpp | 34 +++++++++++++++++--
2 files changed, 38 insertions(+), 2 deletions(-)
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 at -1 2{{while}}
+ foo(const foo&) = default;
+ foo(auto)
+ requires([]<int = 0>() -> bool { return true; }())
+ // expected-error at -1 {{non-constant expression}}
+ // expected-note at -2 {{undefined function}} \
+ // expected-note at -2 {{declared}}
+ {}
+};
+
+// FIXME: This will be fixed by https://github.com/llvm/llvm-project/pull/205557
+struct bar {
+ // expected-note at -1 {{while}}
+ foo x; // check that the lambda gets instantiated.
+};
+
+} // namespace GH115118
+
+#endif
More information about the llvm-branch-commits
mailing list