[clang] [clang][SemaCXX] Fixed a crash when returning an initialization to a top-level deleted function (PR #210973)
Rajveer Singh Bharadwaj via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 21 05:48:44 PDT 2026
https://github.com/Rajveer100 created https://github.com/llvm/llvm-project/pull/210973
Resolves #208488
This crash is caused due to requesting declaration alignment for undeduced types like `auto`.
>From 024a1968b0122a781843a080612b98c8761a96a6 Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer at icloud.com>
Date: Tue, 21 Jul 2026 18:07:30 +0530
Subject: [PATCH] [clang][SemaCXX] Fixed a crash when returning an
initialization to a top-level deleted function
Resolves #208488
This crash is caused due to requesting declaration alignment for
undeduced types like `auto`.
---
clang/docs/ReleaseNotes.md | 1 +
clang/lib/Sema/SemaStmt.cpp | 7 +++++++
clang/test/SemaCXX/deleted-function-return.cpp | 8 ++++++++
3 files changed, 16 insertions(+)
create mode 100644 clang/test/SemaCXX/deleted-function-return.cpp
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 3e6c10666ca16..6db1a1657946d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -839,6 +839,7 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
- Fixed a missing vtable for `dynamic_cast<FinalClass *>(this)` in a function template. (#GH198511)
- Fixed an assertion failure during init-list checking of an array whose element type is an incomplete class. (#GH140685)
- Fixed a crash when using a pack indexing type (e.g. ``Ts...[0]``) imported from another module. (#GH204479)
+- Fixed a crash when returning an initialization to a top-level deleted function. (#GH208488)
#### Bug Fixes to AST Handling
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 27fee88d20c60..721df7be39838 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3466,6 +3466,13 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) {
return NamedReturnInfo();
}
+ const Type *T = VDType.getTypePtr();
+ if (T->getTypeClass() == Type::Auto) {
+ const auto *A = cast<DeducedType>(T);
+ if (A->isUndeducedAutoType())
+ return NamedReturnInfo();
+ }
+
// Variables with higher required alignment than their type's ABI
// alignment cannot use NRVO.
if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() &&
diff --git a/clang/test/SemaCXX/deleted-function-return.cpp b/clang/test/SemaCXX/deleted-function-return.cpp
new file mode 100644
index 0000000000000..9320b85cd1dc8
--- /dev/null
+++ b/clang/test/SemaCXX/deleted-function-return.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only %s
+
+auto f() = delete; // expected-note {{candidate function has been explicitly deleted}}
+
+auto g() {
+ auto x = f(); // expected-error {{call to deleted function 'f'}}
+ return x;
+}
More information about the cfe-commits
mailing list