Skip to content

Commit 1ac3353

Browse files
Fix C++-generating back end issue with dependent multi-dimensional subscripts [GH #195]
1 parent f0e30b6 commit 1ac3353

4 files changed

Lines changed: 51 additions & 7 deletions

File tree

‎src/Changes‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@ behavior standard-mandated. It is now the default behavior, except in
88
Microsoft mode with microsoft_version < 1951.
99

1010

11+
Version 7.1
12+
13+
10/1/26 [GH #195]
14+
C++-generating back end: dependent multi-dimensional subscripts
15+
16+
In cases in which template definitions are generated from the prototype
17+
instantiation IL, when a dependent multi-dimensional subscript operation
18+
appears in a template definition, the C++-generating back end previously
19+
emitted only the first subscript. This is now fixed. For example, with
20+
--c++23:
21+
22+
template<typename T> auto f(const T &t) {
23+
return t[1, 2]; // Previously generated as "t[1]"
24+
}
25+
26+
27+
10/1/26 [GH #191]
28+
C++-generating back end: inaccessible or out-of-scope template arguments
29+
30+
In certain complex cases, the C++-generating back end could put out a
31+
template argument that uses an inaccessible or out-of-scope name, making
32+
the generated code uncompilable. This is now fixed.
33+
34+
1135
Version 7.0, September 28, 2026
1236

1337
9/15/26 [EDGcpfe/28958]

‎src/cp_gen_be.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15255,16 +15255,26 @@ it is a tpck_unknown_function constant and to NULL otherwise.
1525515255
} /* is_dot_static_operation */
1525615256

1525715257

15258-
static void gen_array_subscript(an_expr_node_ptr expr)
15258+
static void gen_array_subscript_list(an_expr_node_ptr expr)
1525915259
/*
15260-
Render the given expression surrounded by brackets.
15260+
Put out the given expression list surrounded by square brackets.
1526115261
*/
1526215262
{
15263+
a_boolean first = TRUE;
15264+
1526315265
write_tok_ch('[');
15264-
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
15265-
/*obj_expr_of_mfunc_operator=*/FALSE);
15266+
while (expr != NULL) {
15267+
if (first) {
15268+
first = FALSE;
15269+
} else {
15270+
write_tok_str(", ");
15271+
} /* if */
15272+
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
15273+
/*obj_expr_of_mfunc_operator=*/FALSE);
15274+
expr = expr->next;
15275+
} /* if */
1526615276
write_tok_ch(']');
15267-
} /* gen_array_subscript */
15277+
} /* gen_array_subscript_list */
1526815278

1526915279

1527015280
static void gen_va_arg(an_expr_node_ptr expr)
@@ -17852,7 +17862,7 @@ handled through recursion.
1785217862
break;
1785317863
case eok_subscript:
1785417864
gen_member_selector_for_builtin_offsetof(arg1);
17855-
gen_array_subscript(arg2);
17865+
gen_array_subscript_list(arg2);
1785617866
break;
1785717867
case eok_cast:
1785817868
case eok_base_class_cast:
@@ -19245,7 +19255,7 @@ gen_expr that might end up generating this expr as a temporary.
1924519255
parens_may_be_needed(generated_precedence[eok_subscript],
1924619256
operand_1),
1924719257
/*obj_expr_of_mfunc_operator=*/FALSE);
19248-
gen_array_subscript(operand_2);
19258+
gen_array_subscript_list(operand_2);
1924919259
goto done_with_operation;
1925019260
case eok_cli_subscript:
1925119261
gen_expr_with_parens(operand_1);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpfe -DTEST_NUMBER=1 --c++23 Test_name.c
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//options_all:--c++23
2+
//type:cp
3+
template<typename T> auto f(const T &t) {
4+
return t[1, 2]; // Previously generated as "t[1]"
5+
}
6+
struct S {
7+
int operator[](int, int) const;
8+
} s;
9+
int i = f(s);

0 commit comments

Comments
 (0)