[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 06:43:23 PDT 2026
https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/210973
>From 1dab7cbaeb33647ceb38052dcef335aa2d532f44 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 | 2 ++
clang/lib/Sema/SemaStmt.cpp | 7 +++++++
clang/test/SemaCXX/deleted-function-return.cpp | 13 +++++++++++++
3 files changed, 22 insertions(+)
create mode 100644 clang/test/SemaCXX/deleted-function-return.cpp
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 28fea9a99b609..d8943d6af7a7d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -334,6 +334,8 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
`[](Types... = args...) {}`). Clang now diagnoses the illegal default
argument instead of asserting. (#GH210714)
+- Fixed a crash when returning an initialization to a top-level deleted function. (#GH208488)
+
#### Bug Fixes to AST Handling
- Fixed a non-deterministic ordering of unused local typedefs that made
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index cc325620883f0..83e0eb9caadca 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3545,6 +3545,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..a0dd145ec0ec9
--- /dev/null
+++ b/clang/test/SemaCXX/deleted-function-return.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only %s
+
+auto f() = delete; // expected-note {{candidate function has been explicitly deleted}}
+
+auto g1() {
+ auto x = f(); // expected-error {{call to deleted function 'f'}}
+ return x;
+}
+
+auto g2() {
+ decltype(auto) x = f(); // expected-error {{call to deleted function 'f'}}
+ return x;
+}
More information about the cfe-commits
mailing list