Page MenuHomePhabricator

[clangd] Fix a hover crash on templated spaceship operator.
ClosedPublic

Authored by adamcz on Oct 26 2021, 4:39 AM.

Details

Summary

We make assumption that:
getDeclForComment(getDeclForComment(X)) == getDeclForComment(X)
but this is not true if you have a template
instantionation of a template instantiation, which is the case when, for
example, you have a <=> operator in a templated class.

This fix makes getDeclForComment() call itself recursively to ensure
this property is always true.

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

Diff Detail

Event Timeline

adamcz created this revision.Oct 26 2021, 4:39 AM
adamcz requested review of this revision.Oct 26 2021, 4:39 AM
kadircet accepted this revision.Oct 26 2021, 7:18 AM
kadircet added inline comments.
clang-tools-extra/clangd/Hover.cpp
269–270

can we also turn these ifs into else ifs (similarly for ifs at the top level) just to make sure we don't change behaviour (i suppose it should be fine, as the TIP will always be null in the case of undeclared specializations, but better safe than sorry).

285

s/instinstantiation/instantiation (unless you intentionally put a double inst :P)

This revision is now accepted and ready to land.Oct 26 2021, 7:18 AM
adamcz updated this revision to Diff 382326.Oct 26 2021, 8:02 AM
adamcz marked 2 inline comments as done.

review comments