Skip to content

[BUG] Returning a tuple with unnamed members #325

Closed
@ntrel

Description

@ntrel

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");
}
  1. 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 {}.

  1. Commenting out d, spurious compile error for e:
rettup.cpp2(1,16): error: int - variable must be initialized on every branch path

There is no declared variable.

  1. Commenting out e, spurious compile error for g:
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.

  1. 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();

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