[PATCH] D116490: [clangd] Code action to declare missing move/copy constructor/assignment

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 31 07:19:27 PDT 2022


sammccall added inline comments.


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp:120
+    // they should be =default or =delete.
+    Inputs.AST->getSema().ForceDeclarationOfImplicitMembers(Class);
+    std::string Code = buildSpecialMemberDeclarations(*Class);
----------------
hokein wrote:
> I think we need this because these members are created lazily in clang, e.g. if the empty struct `s` is not used, there is no constructor decl being created.
> 
> The `ForceDeclarationOfImplicitMembers` is a member function which can mutate the parameter `Class`, I was wondering whether it would lead some bad side-effect, but I didn't come out one (and the mutation is mostly creating a new ctor-decl and adding it to the Class).
That's right. Rewrote the comment to make it clearer that these are lazily created (which is why I think it's safe to create them)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116490



More information about the cfe-commits mailing list