Skip to content
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

Implementation issue forward auto fails to compile #1

Open
aminya opened this issue Oct 11, 2020 · 1 comment
Open

Implementation issue forward auto fails to compile #1

aminya opened this issue Oct 11, 2020 · 1 comment
Assignees
Labels
prototype-bug Something isn't working

Comments

@aminya
Copy link

aminya commented Oct 11, 2020

Thanks for this great proposal!

I was trying this at https://cppx.godbolt.org. I faced this issue that forward auto does not compile:

https://cppx.godbolt.org/z/ezPz7K

#include <iostream>
using namespace std;

auto myfun(in auto x, forward auto y) {
    cout << x << endl;
    y = "goodbye";
    auto z = 0;
    return tuple{y, z};
}


int main() {
    auto [y, z] = myfun(1, string("hey"));
    cout << y <<endl;
    cout << z;
}
Error log
<source>:13:19: error: no matching function for call to 'myfun'

    auto [y, z] = myfun(1, string("hey"));

                  ^~~~~

<source>:4:6: note: candidate ignored; expected deduced type 'auto' but got 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>'

auto myfun(in auto x, forward auto y) {

     ^

1 error generated.

ASM generation compiler returned: 1

<source>:13:19: error: no matching function for call to 'myfun'

    auto [y, z] = myfun(1, string("hey"));

                  ^~~~~

<source>:4:6: note: candidate ignored; expected deduced type 'auto' but got 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>'

auto myfun(in auto x, forward auto y) {

     ^

1 error generated.

Execution build compiler returned: 1

In comparison this compiles:
https://cppx.godbolt.org/z/66YbnT

#include <iostream>
using namespace std;

auto myfun(in auto x, forward string y) {
    cout << x << endl;
    y = "goodbye";
    auto z = 0;
    return tuple{y, z};
}


int main() {
    auto [y, z] = myfun(1, string("hey"));
    cout << y <<endl;
    cout << z;
}

or this
https://cppx.godbolt.org/z/q64YfP

#include <iostream>
using namespace std;

auto myfun(auto x, auto &&y) {
    cout << x << endl;
    y = "goodbye";
    auto z = 0;
    return tuple{y, z};
}


int main() {
    auto [y, z] = myfun(1, string("hey"));
    cout << y <<endl;
    cout << z;
}

Feel free to transfer this issue to the proper repository that contains the actual implementation.

@hsutter
Copy link
Owner

hsutter commented Nov 28, 2020

Thanks, and sorry for the lag. #14 captures that the implementation of forward generally is not yet complete. . This issue is more than a duplicate of 14 so I'll leave it open as well. Both issues should be fixed when forward is completed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prototype-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants