[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

Christian Kandeler via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 08:32:09 PST 2024


================
@@ -490,6 +491,13 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
         BO->getRHS() == OuterImplicit.ASTNode.get<Expr>())
       return false;
   }
+  if (const auto *Decl = Parent->ASTNode.get<VarDecl>()) {
+    if (!Decl->isInitCapture() &&
----------------
ckandeler wrote:

Presumably, with the BinOp check I intended to prevent a false negative for this case:
`int x = 1 + 2 + [[3 + 4 + 5]];`
Apparently, the parser considers the last "+" to be the top-level expression, so we would erroneously fail to offer extraction for the above expression.
However, the same problem already existed for the assignment case, so it's probably wrong anyway to add such a workaround for initialization only. On the other hand, I don't want to introduce a regression either. Do you have a good idea as to how a proper check could look like?


https://github.com/llvm/llvm-project/pull/69477


More information about the cfe-commits mailing list