[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

Viktoriia Bakalova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 15 07:49:16 PDT 2023


VitaNuo added a comment.

thanks!



================
Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:3726
+TEST(Hover, FunctionParameterDefaulValueNotEvaluated) {
+  Annotations T("void foo(int p^aram = 5);");
+  TestTU TU = TestTU::withCode(T.code());
----------------
hokein wrote:
> I believe this case should trigger a crash, but I don't see the crash with a trunk-built clangd, do we miss something here?
It crashes on invalid code. I've inspected two user workspaces:
1.

```
class Foo{};
void foo(Foo param = nullptr);
```

2.
```
void foo(ClassName param = functionReturningObjectOfSimilarSoundingButUnrelatedClass());
```

I guess `clangd` is not even expected to act soundly in the face of non-compiling code. 
But since these crashes are easy to get rid of, and evaluating parameters in function declarations is pointless anyways, we can just avoid these crashes at no extra cost. I cannot use non-compiling code in a hover test, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015



More information about the cfe-commits mailing list