re PR c++/91415 (Invalid warning for C++17 sequencing of shift operator E1<<E2.)
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Aug 2019 12:37:30 +0000 (14:37 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 27 Aug 2019 12:37:30 +0000 (14:37 +0200)
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

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/sequence-pt-4.C [new file with mode: 0644]

index 2ab1c98b26018d101eda8c2d6dc92436e7ee3e27..0376a7b977debc721d1a37ac94a1fe585ee3faaa 100644 (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
index d516deaf24cc83a5b0294927323762232495a0c0..61ee7543dacc447484b2b1955f8366a5f5e1bdc4 100644 (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.  */
index d0a30f93f7c0a49d420605045db9402c312e36ab..64970b28f14f887e5e93f1faf7995dd7512d81f8 100644 (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
diff --git a/gcc/testsuite/g++.dg/warn/sequence-pt-4.C b/gcc/testsuite/g++.dg/warn/sequence-pt-4.C
new file mode 100644 (file)
index 0000000..e8b1e2c
--- /dev/null
@@ -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;
+}