Closed
Description
Possibly this should be an enhancement request. Some of these errors may be because the feature is not implemented? Perhaps I'm using the wrong syntax? If so, better diagnostics would be nice, especially for f
(see 4).
To Reproduce
d: () -> (int, int) = (1,2);
e: () -> (int, int) = { return (1,2); }
f: () -> _ = (5, "hi");
g: () -> (int, std::string) = (5, "hi");
main: () -> int = {
auto [a,b] = f();
assert(a == 5);
assert(b == "hi");
}
d
can't be initialized by an expression:
rettup.cpp2(3,1): error: a function with named return value(s) must have a full { } body
But d
doesn't used named return values. Also f
can be initialized by a tuple expression without needing {}
.
- Commenting out
d
, spurious compile error fore
:
rettup.cpp2(1,16): error: int - variable must be initialized on every branch path
There is no declared variable.
- Commenting out
e
, spurious compile error forg
:
rettup.cpp2(3,19): error: expected , in parameter list (at '::')
rettup.cpp2(3,19): error: missing function return after -> (at '::')
Probably it's parsing std
as an identifier.
- Commenting out
g
,f
compiles OK but doesn't declare or use a tuple struct so the c++ compiler errors:
#line 2 "old/rettup.cpp2"
[[nodiscard]] auto f() -> auto { return 5, "hi"; }
#line 5 "old/rettup.cpp2"
[[nodiscard]] auto main() -> int{
cpp2::assert_in_bounds(auto, a, b) = f();