This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Correct SelectionTree behavior around anonymous field access.
ClosedPublic

Authored by sammccall on Jun 16 2021, 6:27 AM.

Details

Summary

struct A { struct { int b; }; };
A().^b;

This should be considered a reference to b, but currently it's
considered a reference to the anonymous struct field.

Fixes https://github.com/clangd/clangd/issues/798

Diff Detail

Event Timeline

sammccall created this revision.Jun 16 2021, 6:27 AM
sammccall requested review of this revision.Jun 16 2021, 6:27 AM
hokein accepted this revision.Jun 17 2021, 5:08 AM
hokein added inline comments.
clang-tools-extra/clangd/Selection.cpp
71

I still think it is worth to explore this direction (will take a look on this if I have time), but also ok with the current approach.

This revision is now accepted and ready to land.Jun 17 2021, 5:08 AM
sammccall added inline comments.Jun 17 2021, 9:18 AM
clang-tools-extra/clangd/Selection.cpp
71

SG, this isn't urgent so I'll leave this open while out on vacation. I agree it's suspect/suggestive that we need to override the AST source range in exactly one case.

My concern was conceptual: in A().b if you want to describe where the anon field ref happens, I'd pick . or b so placing those outside the range is suspect. Conversely a range of A() seems weird because that's a perfectly valid expression with no dereferencing.

OTOH if you squint I guess this looks a bit like an implicit cast from the A to the anon member. So maybe it's fine and just a question of mental model.