Skip to content

Add support for generic lambda with explicit type list #349

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

Merged

Conversation

filipsajdak
Copy link
Contributor

Currently cppfront process the following code:

main: () = {
    g := :<T> () = { v := 0; };
}

And generates:

auto main() -> int{
    auto g {template <typename T> []() -> void{auto v {0}; }};
}

After this change cppfront will generate:

auto main() -> int{
    auto g {[]<typename T>() -> void{auto v {0}; }};
}

Closes: #346. All regression tests pass.

Currently cppfront process the following code:
```cpp
main: () = {
    g := :<T> () = { v := 0; };
}
```
And generates:
```cpp
auto main() -> int{
    auto g {template <typename T> []() -> void{auto v {0}; }};
}
```
After this change cppfront will generate:
```cpp
auto main() -> int{
    auto g {[]<typename T>() -> void{auto v {0}; }};
}
```

Closes: hsutter#346. All regression tests pass.
@JohelEGP
Copy link
Contributor

JohelEGP commented Apr 10, 2023

Thank you. This fixes #346.

Code:

g: () = :<T> () = { };
f: () = {
  h := :<T> () = { };   // #346
  :<T> (x: T) -> _ = x; // #346
}
id_fn: () -> _ = :<T> (x: T) -> _ = x; // #346
Generated C++1.
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "x.cpp2"
auto g() -> void;
auto f() -> void;

#line 6 "x.cpp2"
[[nodiscard]] auto id_fn() -> auto;

//=== Cpp2 function definitions =================================================

#line 1 "x.cpp2"
auto g() -> void { []<typename T>() -> void{};  }
auto f() -> void{
  auto h {[]<typename T>() -> void{}}; // #346
  []<typename T>(T const& x) -> auto { return x;  };// #346
}
[[nodiscard]] auto id_fn() -> auto { return []<typename T>(T const& x) -> auto { return x;  };  }// #346

@hsutter hsutter merged commit 47fbb70 into hsutter:main Apr 14, 2023
@hsutter
Copy link
Owner

hsutter commented Apr 14, 2023

Sweet! 👏 Thanks @JohelEGP and @filipsajdak . I'm not a big user of explicit template parameter lists on lambdas, so I hadn't noticed yet that that case didn't code gen correctly. Good stuff, appreciated.

@filipsajdak filipsajdak deleted the fsajdak-add-support-for-generic-lambdas branch April 15, 2023 00:23
zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
Currently cppfront process the following code:
```cpp
main: () = {
    g := :<T> () = { v := 0; };
}
```
And generates:
```cpp
auto main() -> int{
    auto g {template <typename T> []() -> void{auto v {0}; }};
}
```
After this change cppfront will generate:
```cpp
auto main() -> int{
    auto g {[]<typename T>() -> void{auto v {0}; }};
}
```

Closes: hsutter#346. All regression tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] _expression-statement_ of unnamed templated function is a template
3 participants