Skip to content

Commit c4e4dc9

Browse files
authored
fix(to_cpp1): lower indexed call in the correct order (#928)
* test: add failing indexed call * fix(to_cpp1): lower indexed call in the correct order
1 parent 7fff368 commit c4e4dc9

5 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
f: (_: i32) = { }
2+
main: () = {
3+
array_of_functions: std::array = (f, f);
4+
index := 0;
5+
arguments: i32 = 0;
6+
array_of_functions[index](arguments);
7+
_ = array_of_functions;
8+
_ = index;
9+
_ = arguments;
10+
}

regression-tests/test-results/gcc-13/pure2-bugfix-for-indexed-call.cpp.output

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
#define CPP2_IMPORT_STD Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
#line 1 "pure2-bugfix-for-indexed-call.cpp2"
10+
11+
12+
//=== Cpp2 type definitions and function declarations ===========================
13+
14+
#line 1 "pure2-bugfix-for-indexed-call.cpp2"
15+
auto f([[maybe_unused]] cpp2::in<cpp2::i32> unnamed_param_1) -> void;
16+
#line 2 "pure2-bugfix-for-indexed-call.cpp2"
17+
auto main() -> int;
18+
19+
//=== Cpp2 function definitions =================================================
20+
21+
#line 1 "pure2-bugfix-for-indexed-call.cpp2"
22+
auto f([[maybe_unused]] cpp2::in<cpp2::i32> unnamed_param_1) -> void{}
23+
#line 2 "pure2-bugfix-for-indexed-call.cpp2"
24+
auto main() -> int{
25+
std::array array_of_functions {f, f};
26+
auto index {0};
27+
cpp2::i32 arguments {0};
28+
CPP2_ASSERT_IN_BOUNDS(array_of_functions, index)(arguments);
29+
static_cast<void>(std::move(array_of_functions));
30+
static_cast<void>(std::move(index));
31+
static_cast<void>(std::move(arguments));
32+
}
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-indexed-call.cpp2... ok (all Cpp2, passes safety checks)
2+

source/to_cpp1.h

+2
Original file line numberDiff line numberDiff line change
@@ -3322,6 +3322,8 @@ class cppfront
33223322
// Handle the suffix operators that remain suffix
33233323
//
33243324
else {
3325+
flush_args();
3326+
33253327
assert(i->op);
33263328
last_was_prefixed = false;
33273329

0 commit comments

Comments
 (0)