Open JohelEGP opened 8 months ago
An alternative is to change back to decltype(auto)
and lower returned member names in parentheses.
That should make -> forward _
return-list "work as expected" more.
The relevant features are https://en.cppreference.com/w/cpp/language/auto and https://en.cppreference.com/w/cpp/language/decltype.
Yet another alternative is to change back to decltype(auto)
,
but reject returning unparenthesized member names.
They should be (member)
or (copy member)
(https://github.com/hsutter/cppfront/issues/466#copy).
Title: Need
decltype(auto)
for perfect backwarding.Description:
At first, a Cpp2
-> forward _
return-list lowered to the Cpp1 return typeauto&&
.175 noted this was unsafe,
and commit b59f539f7275b880d4e623adb473864e49756546 changed it to
decltype(auto)
.274 noted that this makes accessors return by copy,
then commit 413de0ed5747a74e8226c6474072925cf21bacd8 changed it back to
auto&&
, and commit 43cdf3e651ebe51cf1d68efbe50128c248f63364 addressed some safety concerns of #175.Now perfect backwarding doesn't work or returns a temporary. This means we can't implement
std::invoke
or simpler equivalents. For example, implementing a simplefunction_ref
: https://cpp2.godbolt.org/z/r53zfnxbT.Minimal reproducer (https://cpp2.godbolt.org/z/bjjfqEc9e):
Commands:
```bash cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp ```Expected result: Perfect backwarding to work.
Actual result and error:
Cpp2 lowered to Cpp1:
```C++ //=== Cpp2 type declarations ==================================================== #include "cpp2util.h" #line 1 "/app/example.cpp2" //=== Cpp2 type definitions and function declarations =========================== #line 1 "/app/example.cpp2" [[nodiscard]] auto f(cpp2::inOutput:
See also:
175.
274.