[clang] 9b50a88 - [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (#94542)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 21 05:18:18 PDT 2024
Author: Oleksandr T
Date: 2024-06-21T08:18:14-04:00
New Revision: 9b50a88853cc5df4fcdcb56a2ea57f5db4b1978b
URL: https://github.com/llvm/llvm-project/commit/9b50a88853cc5df4fcdcb56a2ea57f5db4b1978b
DIFF: https://github.com/llvm/llvm-project/commit/9b50a88853cc5df4fcdcb56a2ea57f5db4b1978b.diff
LOG: [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (#94542)
Fixes #93512
Added:
clang/test/SemaCXX/lambda-as-default-parameter.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaStmt.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 455c34bce0684..7ac0fa0141b47 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -912,7 +912,8 @@ Bug Fixes to C++ Support
between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (#GH95366).
- Fix immediate escalation bugs in the presence of dependent call arguments. (#GH94935)
- Clang now diagnoses explicit specializations with storage class specifiers in all contexts.
-
+- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a
+ forward-declared class. (#GH93512).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 411e9af26f2b7..1bb86385333ef 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) {
// Variables with higher required alignment than their type's ABI
// alignment cannot use NRVO.
- if (!VD->hasDependentAlignment() &&
+ if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() &&
Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
Info.S = NamedReturnInfo::MoveEligible;
diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
new file mode 100644
index 0000000000000..1f07a7f5644b7
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct a; // expected-note {{forward declaration of 'a'}} \
+ expected-note {{forward declaration of 'a'}}
+void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \
+ expected-error {{variable has incomplete type 'a'}}
More information about the cfe-commits
mailing list