]> gcc.gnu.org Git - gcc.git/commitdiff
c-family: -Wsequence-point and COMPONENT_REF [PR107163]
authorJason Merrill <jason@redhat.com>
Thu, 23 Mar 2023 19:57:39 +0000 (15:57 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 21 Apr 2023 20:27:24 +0000 (16:27 -0400)
The patch for PR91415 fixed -Wsequence-point to treat shifts and ARRAY_REF
as sequenced in C++17, and COMPONENT_REF as well.  But this is unnecessary
for COMPONENT_REF, since the RHS is just a FIELD_DECL with no actual
evaluation, and in this testcase handling COMPONENT_REF as sequenced blows
up fast in a deep inheritance tree.  Instead, look through it.

PR c++/107163

gcc/c-family/ChangeLog:

* c-common.c (verify_tree): Don't use sequenced handling
for COMPONENT_REF.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wsequence-point-5.C: New test.

gcc/c-family/c-common.c
gcc/testsuite/g++.dg/warn/Wsequence-point-5.C [new file with mode: 0644]

index 8105a27ab563c78bb4852b9a7763d344cda257ed..409dbfeec09afaa3d4f7742d8f796c325985f409 100644 (file)
@@ -2006,12 +2006,17 @@ verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
 
     case LSHIFT_EXPR:
     case RSHIFT_EXPR:
-    case COMPONENT_REF:
     case ARRAY_REF:
       if (cxx_dialect >= cxx17)
        goto sequenced_binary;
       goto do_default;
 
+    case COMPONENT_REF:
+      /* Treat as unary, the other operands aren't evaluated.  */
+      x = TREE_OPERAND (x, 0);
+      writer = 0;
+      goto restart;
+
     default:
     do_default:
       /* For other expressions, simply recurse on their operands.
diff --git a/gcc/testsuite/g++.dg/warn/Wsequence-point-5.C b/gcc/testsuite/g++.dg/warn/Wsequence-point-5.C
new file mode 100644 (file)
index 0000000..0354ab0
--- /dev/null
@@ -0,0 +1,37 @@
+// PR c++/107163
+// { dg-additional-options "-Wsequence-point" }
+
+struct BaseType  {
+  int i;
+};
+
+template< int Seq >
+class DerivedType : public DerivedType< Seq - 1 > { };
+
+template<>
+class DerivedType< -1 > : public BaseType { };
+
+int main() {
+  DerivedType< 400 > d;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  d.i = 42;
+  return d.i;
+}
This page took 0.074366 seconds and 5 git commands to generate.