[PATCH] D116218: [clangd] Fix selection on multi-dimensional array.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 28 19:46:56 PST 2021


sammccall added a comment.

Ooh, this is messy indeed. Thanks for digging!



================
Comment at: clang-tools-extra/clangd/Selection.cpp:526
+  // the traversal order of SizeExpr and ElementTypeLoc, which gives a chance
+  // for the SizeExpr to claim its tokens.
+  bool TraverseConstantArrayTypeLoc(ConstantArrayTypeLoc X) {
----------------
I don't think this is a complete solution: won't the inner ArrayTypeLoc still end up owning both sets of brackets?

I think maybe a better solution is making getSourceRange(ArrayTypeLoc) return only ATL.getBracketRange(), and then modify canSafelySkipNode to to avoid pruning based on this small range.

This is vaguely similar to how DeclTypeLoc works today (though in that case the reduced range is the one reported by the AST).


================
Comment at: clang-tools-extra/clangd/Selection.cpp:527
+  // for the SizeExpr to claim its tokens.
+  bool TraverseConstantArrayTypeLoc(ConstantArrayTypeLoc X) {
+    if (!Base::TraverseStmt(X.getSizeExpr()))
----------------
ConstantArrayType isn't the only kind of array, see the other subclasses of ArrayType


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116218



More information about the cfe-commits mailing list