llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clangd] [Signature help] [C++23] Parameter hints do not appear for static operator (and some obscure interaction with templates)

Open timon-ul opened this issue 6 months ago • 13 comments

In the following example code I do not get any parameter hints for the operator, but if I manually type in true clangd recognizes that I am calling the operator.

struct Abc {
    static void operator()(bool a) {}
};

void test() {
    Abc abc;
    abc(^);
}
Image

If I remove the static from the operator definition I do get the paramtere hints.

struct Abc {
    void operator()(bool a) {}
};

void test() {
    Abc abc;
    abc(^);
}
Image

As straight forward as this bug seems to be, I stumbled upon some more odd behaviour. Consider now me using 2 parameters, this still does not work with static as you can see here.

struct Abc {
    static void operator()(bool a, bool b) {}
};

void test() {
    Abc abc;
    abc(^);
}
Image

But if I now template my operator it does work.

struct Abc {
    template <typename T>
    static void operator()(T a, bool b) {}
};

void test() {
    Abc abc;
    abc(^);
}
Image

The odd part here is that I need 2 parameters for my operator, because the templated version with only 1 parameter does not work.

struct Abc {
    template <typename T>
    static void operator()(T a) {}
};

void test() {
    Abc abc;
    abc(^);
}
Image

Also it is important that the template type is used in the parameters, otherwise it does not work.

struct Abc {
    template <typename T>
    static void operator()(bool a, bool b) { T c; }
};

void test() {
    Abc abc;
    abc(^);
}
Image

timon-ul avatar May 06 '26 19:05 timon-ul

@llvm/issue-subscribers-clangd

Author: timon-ul

In the following example code I do not get any parameter hints for the operator, but if I manually type in `true` clangd recognizes that I am calling the operator.

<img width="540" height="300" alt="Image" src="https://github.com/user-attachments/assets/6022fb65-6219-4d0b-949a-a8064f798d0f" />

If I remove the static from the operator definition I do get the paramtere hints.

<img width="527" height="315" alt="Image" src="https://github.com/user-attachments/assets/a437c6f4-3e60-4fbb-8b6f-70c7e687e39f" />

As straight forward as this bug seems to be, I stumbled upon some more odd behaviour. Consider now me using 2 parameters, this still does not work with static as you can see here.

<img width="652" height="301" alt="Image" src="https://github.com/user-attachments/assets/2df5c84a-2052-4885-a0bb-51a600b89631" />

But if I now template my operator it does work.

<img width="635" height="336" alt="Image" src="https://github.com/user-attachments/assets/b9bb201c-4c08-472e-91ee-db8aa49b590d" />

The odd part here is that I need 2 parameters for my operator, because the templated version with only 1 parameter does not work.

<img width="532" height="323" alt="Image" src="https://github.com/user-attachments/assets/ef628ad0-cab3-43a9-a4f5-8b33f07ff509" />

Also it is important that the template type is used in the parameters, otherwise it does not work.

<img width="736" height="346" alt="Image" src="https://github.com/user-attachments/assets/3f0c45ff-de85-4a3d-bdcd-d27ec5c258c3" />

Hi I would like to work on this issue

Ippo47 avatar May 06 '26 22:05 Ippo47

Hi @Ippo47, feel free to work on this issue, I will gladly be your reviewer! I have not yet had the time to do any kind of investigation so far, so I cannot provide you any hints as to where this is going wrong, but otherwise I will happily help you out where I can :) .

timon-ul avatar May 06 '26 22:05 timon-ul

cc @royjacobson as the original implementer of the "static operator()" feature in clang -- perhaps you have ideas or guidance to share.

HighCommander4 avatar May 07 '26 06:05 HighCommander4

I guess the person nuked their account, guess this issue is open for grabs again.

Edit: nvm github just having a hiccups.

timon-ul avatar May 11 '26 09:05 timon-ul

Linking to PR to cross-reference: https://github.com/llvm/llvm-project/pull/197139

HighCommander4 avatar May 12 '26 17:05 HighCommander4

@HighCommander4 ci is failing on test lldb-api.python_api/run_locker/TestRunLocker.py which is unrelated to clangd, all clangd tests passed locally. what should be done?

Ippo47 avatar May 13 '26 09:05 Ippo47

@Ippo47 Without having exactly checked what is going on I want to make you aware that while yes, these tests are unrelated to clangd, the changes you made are NOT in clangd, but in clang/lib/sema and thus there might be an impact on every tool that interacts with clang. To make sure this test failure is not related to your changes check out the commit before your changes and run the test to see if it already failed at that point.

timon-ul avatar May 13 '26 09:05 timon-ul

@timon-ul I ran TestRunLocker.py on the commit just before my changes and it fails even then with the following error: TypeError: expected str, bytes or os.PathLike object, not NoneType Config=x86_64-/usr/bin/clang FAILED (errors=2) This indicates that this error is unrelated to changes made in sema file

Ippo47 avatar May 13 '26 14:05 Ippo47

@HighCommander4 ci is failing on test lldb-api.python_api/run_locker/TestRunLocker.py which is unrelated to clangd, all clangd tests passed locally. what should be done?

I agree that this seems unrelated to the patch and should be safe to ignore.

HighCommander4 avatar May 13 '26 20:05 HighCommander4

Hi @timon-ul, I noticed the existing PR hasn't had activity for a while. I've implemented a fix and opened a draft PR: 234918!. Would you be okay with me moving it forward for review?

@Ippo47, I also wanted to check with you in case you're still working on your PR. Happy to coordinate!

o3wiz avatar Oct 23 '26 12:10 o3wiz

@o3wiz gladly I will review it, thanks for picking this up, I am unsure if we will hear from @Ippo47 anytime soon (but I am happy to be proven wrong too).

timon-ul avatar Oct 23 '26 12:10 timon-ul

Thanks, @timon-ul! The PR is now ready for review, appreciate your help!

o3wiz avatar Oct 23 '26 12:10 o3wiz