[PATCH] D132906: [Clang] Fix lambda CheckForDefaultedFunction(...) so that it checks the CXXMethodDecl is a special member function before attempting to call DefineDefaultedFunction(...)
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 29 18:54:08 PDT 2022
shafik created this revision.
shafik added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
shafik requested review of this revision.
In `Sema::CheckCompletedCXXClass(...)` It used a lambda `CheckForDefaultedFunction` the `CXXMethodDecl` passed to `CheckForDefaultedFunction` may not be a special member function and so before attempting to apply functions that only apply to special member functions it needs to check. It fails to do this before calling `DefineDefaultedFunction(...)`. This PR adds that check and test to verify we no longer crash.
This fixes https://github.com/llvm/llvm-project/issues/57431
https://reviews.llvm.org/D132906
Files:
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1473,3 +1473,13 @@
}
static_assert(g()); // expected-error {{constant expression}} expected-note {{in call}}
}
+
+namespace GH57431 {
+class B{
+ virtual int constexpr f() = 0;
+};
+
+class D : B{
+ virtual int constexpr f() = default; // expected-error {{only special member functions and comparison operators may be defaulted}}
+};
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -6954,7 +6954,8 @@
// Define defaulted constexpr virtual functions that override a base class
// function right away.
// FIXME: We can defer doing this until the vtable is marked as used.
- if (M->isDefaulted() && M->isConstexpr() && M->size_overridden_methods())
+ if (CSM != CXXInvalid && M->isDefaulted() && M->isConstexpr() &&
+ M->size_overridden_methods())
DefineDefaultedFunction(*this, M, M->getLocation());
if (!Incomplete)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132906.456516.patch
Type: text/x-patch
Size: 1234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220830/c80d0d86/attachment.bin>
More information about the cfe-commits
mailing list