Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Content assist + function pointers


> For example, if the type of the function selected in the menu (bar) matches precisely
> the type expected at this point (which foo accepts), then there is a good chance that
> we don't actually want to call the function, but pass it as a function pointer. I
> don't really know how CDT works internally, but I guess that this might be tricky.
> For example, the AST might not include the necessary info at this point, since the
> statement is not syntactically correct yet, so it might be hard to detect that the
> user is typing foo's first parameter.

It's tricky for a different reason. Due to the way overload resolution works in C++, function call expressions (and expressions in general) are resolved "from the inside out". That is, given a function call _expression_, the types of the argument expressions are resolved first, that information is used to select an overload of the function, allowing us to resolve the type of the function call _expression_. It doesn't go the other way: we can't, in general, reason about what type of argument a function call _expression_ "expects" in a given position and use that information to help us come up with the argument _expression_.

That said, we could devise some heuristics that work in a limited set of cases. For example, we could perform name lookup on the name "foo" without having any information about the argument types, resulting in an overload set. If that overload set contains exactly one function, which is a non-template with one argument whose type is a pointer-to-function type matching the signature of "bar", we could offer "bar" itself (rather than a call to bar) as a completion.

I think implementing a heuristic like that is a reasonable request. Please file a bug in the bug tracker so we don't lose track of it.

Thanks,
Nate

Back to the top