-
-
Notifications
You must be signed in to change notification settings - Fork 255
Some ideas on showing overload resolution result #676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @GKxxUCAS, thank you for bringing up this idea. I think the main question is what we want to achieve. You're right, acquiring the overload information isn't hard. I have a local branch for a while now doing that. The transformation of your example looks like this: #include <cstddef>
void foo(long);
void foo(int *);
int main()
{
/* void foo(long) */
/* void foo(int *) USED */
foo(nullptr);
/* void foo(long) USED */
/* void foo(int *) */
foo(NULL);
return 0;
} Your idea about showing why an overload was picked, while very interesting, is way overboard, I think. I don't think Clang gives away this information, which means C++ Insights has to replicate what Clang does. At least, I don't want to maintain such a thing or implement it. Here is one of the starting points: https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaLookup.cpp#L2186 in case you want to take a closer look. Marking the functions, somebody wants the overload information for is an interesting idea. On the other hand, if one already knows the function of interest, the code could be reduced to that, potentially, a single call. The next issue is the representation. In your example, we have only two overloads, but what if there are 8? What if the call in question is part of another call or used as a condition inside, say, an if(/* bool Test(int) USED */
/* bool Test(char) */
/* bool Test(double) */
/* bool Test(float) */
Test(3) && /* bool Test(int) USED */
/* bool Test(char) */
/* bool Test(double) */
/* bool Test(float) */
Test(static_cast<int>(true))) {
} A more compact version could look like this: if(/* bool Test(int) USED
bool Test(char)
bool Test(double)
bool Test(float) */
Test(3) && /* bool Test(int) USED
bool Test(char)
bool Test(double)
bool Test(float) */
Test(static_cast<int>(true))) {
} I don't know if this way would break anything. What do you think and why/for what did you come up with the initial idea? Andreas |
Uh oh!
There was an error while loading. Please reload this page.
It would be nice if C++ Insights can show overload resolution results or even more (e.g. the reason why it is the best match).
e.g. The following code shows why we should prefer
nullptr
toNULL
:Current C++ Insights does no change to this code. I want
I think this is not difficult to achieve. Maybe a command line opt can be added to enable or disable it.
With respect to getting the overload set or knowing whether a call needs overload resolution:
It would be awesome if moreover some explanation can be provided (e.g. Which ones are viable? What are the implicit conversion sequences and what are their ranks? Why is the selected one considered the best match?).
I have to say that the overload resolution rules are massive, and providing explanation for all cases may be impossible. Maybe we can find a subset of those rules that isn't that massive and can handle a great proportion of real-world cases? Personally I think most real-world cases aren't that tricky, and many of them are overloads against different number of arguments, against different class types, const vs non-const, const& vs &&, builtin types vs class types, integers vs floats, etc.
Looking forward to your reply.
The text was updated successfully, but these errors were encountered: