re PR c++/91415 (Invalid warning for C++17 sequencing of shift operator E1<<E2.)

PR c++/91415
	* c-common.c (verify_tree): For LSHIFT_EXPR, RSHIFT_EXPR,
	COMPONENT_REF and ARRAY_REF in cxx_dialect >= cxx17 mode handle it
	like COMPOUND_EXPR rather than normal expression.

	* g++.dg/warn/sequence-pt-4.C: New test.

From-SVN: r274952
This commit is contained in:
Jakub Jelinek 2019-08-27 14:37:30 +02:00 committed by Jakub Jelinek
parent 6c14d00812
commit 6a07489267
4 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,10 @@
2019-08-27 Jakub Jelinek <jakub@redhat.com>
PR c++/91415
* c-common.c (verify_tree): For LSHIFT_EXPR, RSHIFT_EXPR,
COMPONENT_REF and ARRAY_REF in cxx_dialect >= cxx17 mode handle it
like COMPOUND_EXPR rather than normal expression.
2019-08-23 Iain Sandoe <iain@sandoe.co.uk>
PR pch/61250

View file

@ -1889,6 +1889,7 @@ verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
case COMPOUND_EXPR:
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
sequenced_binary:
tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
warn_for_collisions (tmp_nosp);
@ -2031,8 +2032,18 @@ verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
x = TREE_OPERAND (x, 0);
goto restart;
}
gcc_fallthrough ();
goto do_default;
case LSHIFT_EXPR:
case RSHIFT_EXPR:
case COMPONENT_REF:
case ARRAY_REF:
if (cxx_dialect >= cxx17)
goto sequenced_binary;
goto do_default;
default:
do_default:
/* For other expressions, simply recurse on their operands.
Manual tail recursion for unary expressions.
Other non-expressions need not be processed. */

View file

@ -1,3 +1,8 @@
2019-08-27 Jakub Jelinek <jakub@redhat.com>
PR c++/91415
* g++.dg/warn/sequence-pt-4.C: New test.
2019-08-27 Robin Dapp <rdapp@linux.ibm.com>
PR testsuite/91549

View file

@ -0,0 +1,21 @@
/* More sequence point warning tests */
/* { dg-do compile } */
/* { dg-options "-Wsequence-point" } */
struct S { int a[10]; };
void bar (int, int, int, int, int, int, int, int);
int
foo (int i, int x[10][10], int y[10], struct S z[10], struct S *w[10])
{
int b = x[i++][i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
int c = i++ << i++; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
int d = i++ >> i++; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
int e = i++ && i++;
int f = i++ ? i++ : i++;
int g = (i++, i++);
int h = z[i++].a[i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
int j = w[i++]->a[i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
bar (b, c, d, e, f,g, h, j);
return i;
}