Skip to content

[BUG] Return-by broken by "return expression list" support #408

Closed
@JohelEGP

Description

@JohelEGP

Title: Return-by broken by ab29f19.

That's my guess.

Minimal reproducer (https://cpp2.godbolt.org/z/Yh95zcrT1):

f: (forward x) -> forward _ = (forward x);
g: (forward x) -> forward _ = { return (forward x); }
main: () = { }

Commands:

cppfront -clean-cpp1 main.cpp2
clang++17 -std=c++2b -stdlib=libc++ -lc++abi -I . main.cpp

Expected result:

[[nodiscard]] auto f(auto&& x) -> auto&& { return CPP2_FORWARD(x);  }
[[nodiscard]] auto g(auto&& x) -> auto&&{return CPP2_FORWARD(x); }

Actual result and error:

[[nodiscard]] auto f(auto&& x) -> auto&& { return { CPP2_FORWARD(x) };  }
[[nodiscard]] auto g(auto&& x) -> auto&&{return { CPP2_FORWARD(x) }; }
Cpp2 lowered to Cpp1.
#include "cpp2util.h"


[[nodiscard]] auto f(auto&& x) -> auto&&;
[[nodiscard]] auto g(auto&& x) -> auto&&;
auto main() -> int;

[[nodiscard]] auto f(auto&& x) -> auto&& { return { CPP2_FORWARD(x) };  }
[[nodiscard]] auto g(auto&& x) -> auto&&{return { CPP2_FORWARD(x) }; }
auto main() -> int{}
main.cpp2:1:51: error: cannot deduce return type from initializer list
[[nodiscard]] auto f(auto&& x) -> auto&& { return { CPP2_FORWARD(x) };  }
                                                  ^~~~~~~~~~~~~~~~~~~
main.cpp2:2:49: error: cannot deduce return type from initializer list
[[nodiscard]] auto g(auto&& x) -> auto&&{return { CPP2_FORWARD(x) }; }
                                                ^~~~~~~~~~~~~~~~~~~
2 errors generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions