[PATCH] D64556: [clangd] Fix an assertion crash in "ExtractVariable" tweak

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 04:23:06 PDT 2019


sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/clangd/Selection.cpp:361
     return nullptr;
   for (const Node *Ancestor = Root;; Ancestor = Ancestor->Children.front()) {
+    assert(Ancestor && "Ancestor can not be null");
----------------
can we just rewrite this as

```
while (Root->Children.size() == 1 && !Root->Selected)
  Ancestor = Ancestor->Children.front();
return Root;
```

seems a lot clearer, not sure what I was thinking when I wrote this...


================
Comment at: clang-tools-extra/clangd/Selection.cpp:368
   }
-  return nullptr;
+  llvm_unreachable("must not reach here!");
 }
----------------
there's no termination condition for the loop. If there were, the compiler would warn us.
I think we don't need this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64556





More information about the cfe-commits mailing list