Skip to content

Commit dc90649

Browse files
committed
c++: Fix a pasto in the PR120471 fix [PR120940]
No idea how this slipped in, I'm terribly sorry. Strangely nothing in the testsuite has caught this, so I've added a new test for that. 2025-07-03 Jakub Jelinek <jakub@redhat.com> PR c++/120940 * typeck.cc (cp_build_array_ref): Fix a pasto. * g++.dg/parse/pr120940.C: New test. * g++.dg/warn/Wduplicated-branches9.C: New test.
1 parent ddab5cf commit dc90649

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

gcc/cp/typeck.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,7 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
40044004
tree op0, op1, op2;
40054005
op0 = TREE_OPERAND (array, 0);
40064006
op1 = TREE_OPERAND (array, 1);
4007-
op2 = TREE_OPERAND (array, 1);
4007+
op2 = TREE_OPERAND (array, 2);
40084008
if (TREE_SIDE_EFFECTS (idx) || !tree_invariant_p (idx))
40094009
{
40104010
/* If idx could possibly have some SAVE_EXPRs, turning
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// PR c++/120940
2+
// { dg-do run }
3+
4+
int a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5+
int b[8] = { 9, 10, 11, 12, 13, 14, 15, 16 };
6+
7+
__attribute__((noipa)) int
8+
foo (int x, int y)
9+
{
10+
return (x ? a : b)[y];
11+
}
12+
13+
int
14+
main ()
15+
{
16+
if (foo (1, 4) != 5 || foo (0, 6) != 15)
17+
__builtin_abort ();
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// PR c++/120940
2+
// { dg-do compile }
3+
// { dg-options "-Wduplicated-branches" }
4+
5+
static char a[16][8], b[16][8];
6+
7+
char *
8+
foo (int x, int y)
9+
{
10+
return (x ? a : b)[y];
11+
}

0 commit comments

Comments
 (0)