708
708 copied to clipboard
Implementation issue `forward auto` fails to compile
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.
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!