[PATCH] D72163: [clangd] targetDecl() returns only NamedDecls.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 3 08:40:17 PST 2020


sammccall created this revision.
sammccall added reviewers: kadircet, ilya-biryukov.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.

While it's perfectly reasonable for non-named decls such as
static_assert to resolve to themselves:

- nothing else ever resolves to them
- features based on references (hover, highlight, find refs etc) tend to be uninteresting where only trivial references are possible
- returning NamedDecl is a more convenient API (we cast to it in many places)
- this aligns closer to findExplicitReferences/explicitReferenceTargets

This fixes a crash in explicitReferenceTargets: if the target is a
non-named decl then there's an invalid unchecked cast to NamedDecl.

In practice this means when hovering over e.g. a static_assert:

- before ac3f9e4842 <https://reviews.llvm.org/rGac3f9e48421712168884d59cbfe8b294dd76a19b>, we would show a (boring) hover card
- after ac3f9e4842 <https://reviews.llvm.org/rGac3f9e48421712168884d59cbfe8b294dd76a19b>, we would crash
- after this patch, we will show nothing


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72163

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/FindTarget.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72163.236073.patch
Type: text/x-patch
Size: 11614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200103/7442d860/attachment-0001.bin>


More information about the cfe-commits mailing list