[clang-tools-extra] 84051d8 - [clangd] Fix a declare-constructor tweak crash on incomplete fields.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 21 10:51:46 PDT 2022
Author: Haojian Wu
Date: 2022-04-21T19:44:43+02:00
New Revision: 84051d8226d517f7728750ec4bde3ba75ca03468
URL: https://github.com/llvm/llvm-project/commit/84051d8226d517f7728750ec4bde3ba75ca03468
DIFF: https://github.com/llvm/llvm-project/commit/84051d8226d517f7728750ec4bde3ba75ca03468.diff
LOG: [clangd] Fix a declare-constructor tweak crash on incomplete fields.
Differential Revision: https://reviews.llvm.org/D124154
Added:
Modified:
clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp b/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
index a00b778e7dd79..bc0f4e1ce2569 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
@@ -178,6 +178,8 @@ class MemberwiseConstructor : public Tweak {
// Decide what to do with a field of type C.
static FieldAction considerClassValue(const CXXRecordDecl &C) {
+ if (!C.hasDefinition())
+ return Skip;
// We can't always tell if C is copyable/movable without doing Sema work.
// We assume operations are possible unless we can prove not.
bool CanCopy = C.hasUserDeclaredCopyConstructor() ||
diff --git a/clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
index cc2750d557c8d..58671af9915e5 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
@@ -23,6 +23,8 @@ TWEAK_TEST(MemberwiseConstructor);
TEST_F(MemberwiseConstructorTest, Availability) {
EXPECT_AVAILABLE("^struct ^S ^{ int x, y; };");
+ // Verify no crashes on incomplete member fields.
+ EXPECT_UNAVAILABLE("/*error-ok*/class Forward; class ^A { Forward f;}");
EXPECT_UNAVAILABLE("struct S { ^int ^x, y; }; struct ^S;");
EXPECT_UNAVAILABLE("struct ^S {};");
EXPECT_UNAVAILABLE("union ^S { int x; };");
More information about the cfe-commits
mailing list