[clang] [Clang] incorrect assertion when checking template template parameter of a lambda (PR #138121)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 08:01:03 PDT 2025
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/138121
>From 34011def1ec643701a84424f0813484efa39a1d1 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Thu, 1 May 2025 13:32:00 +0200
Subject: [PATCH 1/2] [Clang] incorrect assertion when checking template
template parameter of a lambda.
When a lamdbda is used in an alias declaration, we were trying
to refer to its call operator. However, that could happen before
(or during) the call operator is defined.
So we should not assume a lambda always has a call operator.
Fixes #136432
Fixes #137014
Fixes #138018
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/AST/DeclCXX.cpp | 6 +++++-
clang/test/SemaCXX/lambda-unevaluated.cpp | 16 ++++++++++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5cd1fbeabcfe..8a463f9aca0c9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -529,6 +529,8 @@ Bug Fixes to C++ Support
- Clang now issues an error when placement new is used to modify a const-qualified variable
in a ``constexpr`` function. (#GH131432)
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)
+- Fix a crash when checking the template template parameters of a dependent lambda appearing in an alias declaration.
+ (#GH136432), (#GH137014), (#GH138018)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 4d07efd58f518..9095575ee1175 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1696,7 +1696,11 @@ static NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) {
RD.getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
DeclContext::lookup_result Calls = RD.lookup(Name);
- assert(!Calls.empty() && "Missing lambda call operator!");
+
+ // This can happen while building the lambda.
+ if (Calls.empty())
+ return nullptr;
+
assert(allLookupResultsAreTheSame(Calls) &&
"More than one lambda call operator!");
diff --git a/clang/test/SemaCXX/lambda-unevaluated.cpp b/clang/test/SemaCXX/lambda-unevaluated.cpp
index a9bcab58464e2..40f8a729fd912 100644
--- a/clang/test/SemaCXX/lambda-unevaluated.cpp
+++ b/clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -266,3 +266,19 @@ void func() {
}
} // namespace GH88081
+
+namespace GH138018 {
+
+template <typename T> struct vec {};
+
+auto structure_to_typelist(auto) {
+ return []<template <typename> typename T>(T<int>) {
+ return 0;
+ }(vec<int>{});
+}
+
+template <typename T> using helper = decltype(structure_to_typelist(T{}));
+static_assert(__is_same_as(int, helper<int>));
+
+
+} // namespace GH138018
>From 6930f81e01ce00009e28d2a0d95c03a65a5877ce Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Thu, 1 May 2025 17:00:34 +0200
Subject: [PATCH 2/2] add assert
---
clang/lib/AST/DeclCXX.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 9095575ee1175..a3b3478e4b26a 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1754,6 +1754,7 @@ CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const {
CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
CXXMethodDecl *CallOp = getLambdaCallOperator();
+ assert(CallOp && "null call operator");
CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv();
return getLambdaStaticInvoker(CC);
}
More information about the cfe-commits
mailing list