[PATCH] D124154: [clangd] Fix a declare-constructor tweak crash on incomplete fields.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 21 10:51:48 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG84051d8226d5: [clangd] Fix a declare-constructor tweak crash on incomplete fields. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124154/new/

https://reviews.llvm.org/D124154

Files:
  clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
  clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
@@ -23,6 +23,8 @@
 
 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; };");
Index: clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
@@ -178,6 +178,8 @@
 
   // 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() ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124154.424248.patch
Type: text/x-patch
Size: 1377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220421/0423632b/attachment.bin>


More information about the cfe-commits mailing list