Skip to content

[BUG] No support for multi-argument indexing #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohelEGP opened this issue Jun 1, 2023 · 0 comments · Fixed by #483
Closed

[BUG] No support for multi-argument indexing #482

JohelEGP opened this issue Jun 1, 2023 · 0 comments · Fixed by #483
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Jun 1, 2023

Title: No support for multi-argument indexing.

Description:

An expression like x[y,z]
lowers to cpp2::assert_in_bounds(x, y, z),
but has an arity of 2.

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

t: type = {
  operator[]: (inout this, x: _, y: _) -> i32 = 42;
}
main: () = {
  [[assert: t()[1, 2] == 42]]
}
Commands:
cppfront -clean-cpp1 main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp

Expected result:

It doesn't seem trivial to support multi-argument indexing in cpp2::assert_in_bounds.
See https://en.cppreference.com/w/cpp/container/mdspan/operator_at.

  cpp2::Default.expects(t()[1, 2]==42, "");

Actual result and error:

  cpp2::Default.expects(cpp2::assert_in_bounds(t(), 1, 2)==42, "");
Cpp2 lowered to Cpp1.
#include "cpp2util.h"

class t;
  
class t {
  public: [[nodiscard]] auto operator[](auto const& x, auto const& y) -> cpp2::i32;

  public: t() = default;
  public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
  public: auto operator=(t const&) -> void = delete;
};
auto main() -> int;
  

  [[nodiscard]] auto t::operator[](auto const& x, auto const& y) -> cpp2::i32 { return 42;  }

auto main() -> int{
  cpp2::Default.expects(cpp2::assert_in_bounds(t(), 1, 2)==42, "");
}
Output.
build/_cppfront/main.cpp:20:25: error: no matching function for call to 'assert_in_bounds'
  cpp2::Default.expects(cpp2::assert_in_bounds(t(), 1, 2)==42, "");
                        ^~~~~~~~~~~~~~~~~~~~~~
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:399:6: note: candidate function template not viable: requires 2 arguments, but 3 were provided
auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
     ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:407:6: note: candidate function template not viable: requires 2 arguments, but 3 were provided
auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
     ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant