Skip to content

auto lambda parameters are not deduced #5527

@alexweej

Description

@alexweej

Type: LanguageService

Describe the bug

  • OS and Version: Ubuntu 19.10
  • VS Code Version: 1.44.2
  • C/C++ Extension Version: 0.28.0
  • Other extensions you installed (and if the issue persists after disabling them): n/a
  • Does this issue involve using SSH remote to run the extension on a remote machine?: no
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).

Sometimes functions/methods/constructors take a callable object and it's useful and common to write a lambda directly in the call. However, doing so currently requires spelling the type of the argument in full in order to get VS Code's full support for checking and completion. Consider e.g.

some_future.then([](auto const& value) {
    // what is `value`?
});

Given that the type of some_future is known (let's call it whatever_future<std::string>) it seems reasonable given an appropriate definition of whatever_future<T>::then that the type of value is correctly deduced to be std::string const&.

A complete example that demonstrates the problem:

#include <string>

template <typename Callable>
auto make_something(Callable&& callable) {
    callable(std::string{"foobar"});
};

auto test() {
    make_something([](auto const& something) {
        something.size(); // here `something` is just `auto`
    });
}

The equivalent in TypeScript works fine:

function makeSomething(callable: (_: string) => void) {
    callable("foobar");
}

function test() {
    makeSomething(something => {
        something.length;
    });
}

I note however that TypeScript does have a clear interface type for the callable that explains everything that's needed. In the C++ example the actual definition of the templated function needs to be used, because unless I'm missing something new and shiny with regards to Concepts, there is no good way to express the same information. But I may be wrong on that!

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Language ServiceVisual StudioInherited from Visual Studiobugmore votes neededIssues that have been postponed until more community members upvote it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions