Hi! The following patch adds some tweaks for -Wsequence-point warning for C++17 and later. In particular, stop warning about no sequence point in between <<, >>, ., -> and [] expressions, where E1 is in C++17 sequenced before E2.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? As mentioned in the PR, this is just part of the needed changes, I've tried to adjust handling of MODIFY_EXPR, but didn't figure out exactly what needs to be done, and .* / ->* aren't handled either, and CALL_EXPR needs probably some verification too. 2019-08-12 Jakub Jelinek <ja...@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. * g++.dg/warn/sequence-pt-4.C: New test. --- gcc/c-family/c-common.c.jj 2019-08-12 09:45:54.463491950 +0200 +++ gcc/c-family/c-common.c 2019-08-12 12:01:32.783135654 +0200 @@ -1889,6 +1889,7 @@ verify_tree (tree x, struct tlist **pbef 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 +2035,18 @@ verify_tree (tree x, struct tlist **pbef 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. */ --- gcc/testsuite/g++.dg/warn/sequence-pt-4.C.jj 2019-08-12 12:16:27.205660149 +0200 +++ gcc/testsuite/g++.dg/warn/sequence-pt-4.C 2019-08-12 12:22:07.540530959 +0200 @@ -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; +} Jakub