public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.
@ 2008-08-12 15:18 Manuel López-Ibáñez
  2008-08-25  8:00 ` Manuel López-Ibáñez
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel López-Ibáñez @ 2008-08-12 15:18 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 538 bytes --]

Testcases come from the C testsuite.

Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,ada

OK for trunk?

2008-08-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/17880
cp/
	* semantics.c (begin_if_stmt): Call verify_sequence_points.
	(begin_while_stmt): Likewise.
	(finish_do_body): Likewise.
	(finish_return_stmt): Likewise.
	(finish_for_init_stmt): Likewise.
	(finish_switch_condition): Likewise.
testsuite/
	* g++.dg/warn/sequence-pt-1.C: New.
	* g++.dg/warn/sequence-pt-pr17880.C: New.

[-- Attachment #2: fix-pr17880.diff --]
[-- Type: text/plain, Size: 11880 bytes --]

Index: gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C
===================================================================
--- gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C	(revision 0)
@@ -0,0 +1,54 @@
+// PR 17880
+// { dg-do compile }
+// { dg-options "-Wsequence-point" }
+
+int
+foo (int x)
+{
+  unsigned int a;
+  int b;
+
+  b = (a += 5) > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a += 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a -= 5) > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a -= 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = a-- > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = a-- + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = ++a > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = ++a + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+
+  if ((a += 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a += 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a -= 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a -= 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (a-- > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (a-- + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (++a > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (++a + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  do {} while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  for ((a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
+  for (b = (a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
+  for (; (a += 5) > a;);  // { dg-warning "undefined" "sequence point warning" }
+  for (;; b = (a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  for (;; a++ + a++);  // { dg-warning "undefined" "sequence point warning" }
+  if (a) a++ - a--;    // { dg-warning "undefined" "sequence point warning" }
+  ((a +=5) > a) ? a : b; // { dg-warning "undefined" "sequence point warning" }
+  return (a++ - a--); // { dg-warning "undefined" "sequence point warning" }
+}
+
+void bar (int i)
+{
+  int a = i++ - i++; // { dg-warning "undefined" "sequence point warning" }
+} 
+
+void baz (int i)
+{
+  switch (i++ + i++)  // { dg-warning "undefined" "sequence point warning" }
+    {
+    case 1:
+      i++ - i++;  // { dg-warning "undefined" "sequence point warning" }
+    case 2:
+      break;
+    }
+}
Index: gcc/testsuite/g++.dg/warn/sequence-pt-1.C
===================================================================
--- gcc/testsuite/g++.dg/warn/sequence-pt-1.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/sequence-pt-1.C	(revision 0)
@@ -0,0 +1,109 @@
+/* Test for sequence point warnings.  */
+/* Origin: Michael Meeks in
+   <URL:http://gcc.gnu.org/ml/gcc-patches/1998-06/msg00316.html>,
+   adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>.  */
+/* { dg-do compile } */
+/* { dg-options "-Wsequence-point" } */
+
+struct s
+{
+  int a;
+};
+
+extern int fn (int);
+extern int fnb (int, int);
+extern int fnc (int *);
+extern int sprintf (char *, const char *, ...);
+
+typedef __SIZE_TYPE__ size_t;
+
+void
+foo (int a, int b, int n, int p, int *ptr, struct s *sptr,
+     int *ap, int *bp, int **cp, char *ans, int (*fnp[8])(int))
+{
+  int len;
+    
+  a = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = --a; /* { dg-warning "undefined" "sequence point warning" } */
+  a = ++a + b; /* { dg-warning "undefined" "sequence point warning" } */
+  a = a-- + b; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[n] = bp[n++]; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[--n] = bp[n]; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[++n] = bp[--n]; /* { dg-warning "undefined" "sequence point warning" } */
+  cp[n][n] = cp[n][n]++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
+  cp[n][p] = cp[n][n++]; /* { dg-warning "undefined" "sequence point warning" } */
+  *ptr++ = (size_t)ptr++; /* { dg-warning "undefined" "sequence point warning" } */
+  sptr->a = sptr->a++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
+  sptr->a = (size_t)(sptr++); /* { dg-warning "undefined" "sequence point warning" } */
+  *ptr++ = fn (*ptr); /* { dg-warning "undefined" "sequence point warning" } */
+  a = b = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  b = a = --b; /* { dg-warning "undefined" "sequence point warning" } */
+  a = 1 + (a = 1); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (a = b); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (a = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
+  a = (bp[a++] = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
+  a = b++ * b++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = fnb (b++, b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b++]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b++]) (b); /* { dg-warning "undefined" "sequence point warning" } */
+  *ap = fnc (ap++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a += b) + (a += n); /* { dg-warning "undefined" "sequence point warning" } */
+  a =  (b, b++) + (b++, b); /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a++] += a; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a+=1] += a; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a++] += a++; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a+=1] += a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = a++, b = a; /* { dg-warning "undefined" "sequence point warning" } */
+  b = a, a = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = (b++ ? n : a) + b; /* { dg-warning "undefined" "sequence point warning" } */
+  b ? a = a++ : a; /* { dg-warning "undefined" "sequence point warning" } */
+  b && (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a = a++) && b; /* { dg-warning "undefined" "sequence point warning" } */
+  b, (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a = a++), b; /* { dg-warning "undefined" "sequence point warning" } */
+  a ^= b ^= a ^= b; /* { dg-warning "undefined" "sequence point warning" } */
+
+  a = a; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = ! (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = - (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (double) (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  len = sprintf (ans, "%d", len++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = fn (a++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  b++, (b + b); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  (a = b++), (a = b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++, b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = b++ && b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = b++ || b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++ ? b++ : a); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++ ? a : b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  ap[a++] += bp[b]; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  ap[a += 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  *ptr < 128 ? *ptr++ : *(ptr += 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+
+  /* The following will be represented internally with a tree consisting of
+     many duplicated SAVE_EXPRs.  This caused the previous version of the
+     sequence point warning code to fail by running out of virtual memory.  */
+  a = ((b & 1 ? 21 : 0)
+       | (b & 2 ? 22 : 0)
+       | (b & 3 ? 23 : 0)
+       | (b & 4 ? 24 : 0)
+       | (b & 5 ? 25 : 0)
+       | (b & 6 ? 26 : 0)
+       | (b & 7 ? 27 : 0)
+       | (b & 8 ? 28 : 0)
+       | (b & 9 ? 29 : 0)
+       | (b & 10 ? 30 : 0)
+       | (b & 11 ? 31 : 0)
+       | (b & 12 ? 32 : 0)
+       | (b & 13 ? 1 : 0)
+       | (b & 14 ? 2 : 0)
+       | (b & 15 ? 3 : 0)
+       | (b & 16 ? 4 : 0)
+       | (b & 17 ? 5 : 0)
+       | (b & 18 ? 6 : 0)
+       | (b & 19 ? 7 : 0)
+       | (b & 20 ? 8 : 0)
+       | (b & 21 ? 9 : 0));
+}
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 138700)
+++ gcc/cp/semantics.c	(working copy)
@@ -658,10 +658,13 @@ begin_if_stmt (void)
    IF_STMT.  */
 
 void
 finish_if_stmt_cond (tree cond, tree if_stmt)
 {
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
   add_stmt (if_stmt);
   THEN_CLAUSE (if_stmt) = push_stmt_list ();
 }
 
@@ -722,10 +725,12 @@ begin_while_stmt (void)
    WHILE_STMT.  */
 
 void
 finish_while_stmt_cond (tree cond, tree while_stmt)
 {
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
   finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond));
   simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
 }
 
 /* Finish a while-statement, which may be given by WHILE_STMT.  */
@@ -769,10 +774,12 @@ finish_do_body (tree do_stmt)
 
 void
 finish_do_stmt (tree cond, tree do_stmt)
 {
   cond = maybe_convert_cond (cond);
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
   DO_COND (do_stmt) = cond;
   finish_stmt ();
 }
 
 /* Finish a return-statement.  The EXPRESSION returned, if any, is as
@@ -788,10 +795,13 @@ finish_return_stmt (tree expr)
 
   if (flag_openmp && !check_omp_return ())
     return error_mark_node;
   if (!processing_template_decl)
     {
+      if (warn_sequence_point)
+	verify_sequence_points (expr);
+      
       if (DECL_DESTRUCTOR_P (current_function_decl)
 	  || (DECL_CONSTRUCTOR_P (current_function_decl)
 	      && targetm.cxx.cdtor_returns_this ()))
 	{
 	  /* Similarly, all destructors must run destructors for
@@ -847,10 +857,13 @@ finish_for_init_stmt (tree for_stmt)
    FOR_STMT.  */
 
 void
 finish_for_cond (tree cond, tree for_stmt)
 {
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond));
   simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
 }
 
 /* Finish the increment-EXPRESSION in a for-statement, which may be
@@ -976,10 +989,13 @@ finish_switch_cond (tree cond, tree swit
 	    cond = index;
 	}
     }
   if (check_for_bare_parameter_packs (cond))
     cond = error_mark_node;
+  else if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
   add_stmt (switch_stmt);
   push_switch (switch_stmt);
   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.
  2008-08-12 15:18 PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc Manuel López-Ibáñez
@ 2008-08-25  8:00 ` Manuel López-Ibáñez
  2008-08-25 17:29   ` Mark Mitchell
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel López-Ibáñez @ 2008-08-25  8:00 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 772 bytes --]

PING: http://gcc.gnu.org/ml/gcc-patches/2008-08/msg00790.html

2008/8/12 Manuel López-Ibáñez <lopezibanez@gmail.com>:
> Testcases come from the C testsuite.
>
> Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
> --enable-languages=all,ada
>
> OK for trunk?
>
> 2008-08-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
>
>        PR c++/17880
> cp/
>        * semantics.c (begin_if_stmt): Call verify_sequence_points.
>        (begin_while_stmt): Likewise.
>        (finish_do_body): Likewise.
>        (finish_return_stmt): Likewise.
>        (finish_for_init_stmt): Likewise.
>        (finish_switch_condition): Likewise.
> testsuite/
>        * g++.dg/warn/sequence-pt-1.C: New.
>        * g++.dg/warn/sequence-pt-pr17880.C: New.
>

[-- Attachment #2: fix-pr17880.diff --]
[-- Type: text/plain, Size: 11880 bytes --]

Index: gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C
===================================================================
--- gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C	(revision 0)
@@ -0,0 +1,54 @@
+// PR 17880
+// { dg-do compile }
+// { dg-options "-Wsequence-point" }
+
+int
+foo (int x)
+{
+  unsigned int a;
+  int b;
+
+  b = (a += 5) > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a += 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a -= 5) > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a -= 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = a-- > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = a-- + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = ++a > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = ++a + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+
+  if ((a += 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a += 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a -= 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a -= 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (a-- > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (a-- + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (++a > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (++a + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  do {} while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  for ((a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
+  for (b = (a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
+  for (; (a += 5) > a;);  // { dg-warning "undefined" "sequence point warning" }
+  for (;; b = (a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  for (;; a++ + a++);  // { dg-warning "undefined" "sequence point warning" }
+  if (a) a++ - a--;    // { dg-warning "undefined" "sequence point warning" }
+  ((a +=5) > a) ? a : b; // { dg-warning "undefined" "sequence point warning" }
+  return (a++ - a--); // { dg-warning "undefined" "sequence point warning" }
+}
+
+void bar (int i)
+{
+  int a = i++ - i++; // { dg-warning "undefined" "sequence point warning" }
+} 
+
+void baz (int i)
+{
+  switch (i++ + i++)  // { dg-warning "undefined" "sequence point warning" }
+    {
+    case 1:
+      i++ - i++;  // { dg-warning "undefined" "sequence point warning" }
+    case 2:
+      break;
+    }
+}
Index: gcc/testsuite/g++.dg/warn/sequence-pt-1.C
===================================================================
--- gcc/testsuite/g++.dg/warn/sequence-pt-1.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/sequence-pt-1.C	(revision 0)
@@ -0,0 +1,109 @@
+/* Test for sequence point warnings.  */
+/* Origin: Michael Meeks in
+   <URL:http://gcc.gnu.org/ml/gcc-patches/1998-06/msg00316.html>,
+   adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>.  */
+/* { dg-do compile } */
+/* { dg-options "-Wsequence-point" } */
+
+struct s
+{
+  int a;
+};
+
+extern int fn (int);
+extern int fnb (int, int);
+extern int fnc (int *);
+extern int sprintf (char *, const char *, ...);
+
+typedef __SIZE_TYPE__ size_t;
+
+void
+foo (int a, int b, int n, int p, int *ptr, struct s *sptr,
+     int *ap, int *bp, int **cp, char *ans, int (*fnp[8])(int))
+{
+  int len;
+    
+  a = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = --a; /* { dg-warning "undefined" "sequence point warning" } */
+  a = ++a + b; /* { dg-warning "undefined" "sequence point warning" } */
+  a = a-- + b; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[n] = bp[n++]; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[--n] = bp[n]; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[++n] = bp[--n]; /* { dg-warning "undefined" "sequence point warning" } */
+  cp[n][n] = cp[n][n]++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
+  cp[n][p] = cp[n][n++]; /* { dg-warning "undefined" "sequence point warning" } */
+  *ptr++ = (size_t)ptr++; /* { dg-warning "undefined" "sequence point warning" } */
+  sptr->a = sptr->a++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
+  sptr->a = (size_t)(sptr++); /* { dg-warning "undefined" "sequence point warning" } */
+  *ptr++ = fn (*ptr); /* { dg-warning "undefined" "sequence point warning" } */
+  a = b = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  b = a = --b; /* { dg-warning "undefined" "sequence point warning" } */
+  a = 1 + (a = 1); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (a = b); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (a = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
+  a = (bp[a++] = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
+  a = b++ * b++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = fnb (b++, b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b++]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b++]) (b); /* { dg-warning "undefined" "sequence point warning" } */
+  *ap = fnc (ap++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a += b) + (a += n); /* { dg-warning "undefined" "sequence point warning" } */
+  a =  (b, b++) + (b++, b); /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a++] += a; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a+=1] += a; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a++] += a++; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a+=1] += a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = a++, b = a; /* { dg-warning "undefined" "sequence point warning" } */
+  b = a, a = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = (b++ ? n : a) + b; /* { dg-warning "undefined" "sequence point warning" } */
+  b ? a = a++ : a; /* { dg-warning "undefined" "sequence point warning" } */
+  b && (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a = a++) && b; /* { dg-warning "undefined" "sequence point warning" } */
+  b, (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a = a++), b; /* { dg-warning "undefined" "sequence point warning" } */
+  a ^= b ^= a ^= b; /* { dg-warning "undefined" "sequence point warning" } */
+
+  a = a; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = ! (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = - (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (double) (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  len = sprintf (ans, "%d", len++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = fn (a++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  b++, (b + b); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  (a = b++), (a = b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++, b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = b++ && b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = b++ || b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++ ? b++ : a); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++ ? a : b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  ap[a++] += bp[b]; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  ap[a += 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  *ptr < 128 ? *ptr++ : *(ptr += 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+
+  /* The following will be represented internally with a tree consisting of
+     many duplicated SAVE_EXPRs.  This caused the previous version of the
+     sequence point warning code to fail by running out of virtual memory.  */
+  a = ((b & 1 ? 21 : 0)
+       | (b & 2 ? 22 : 0)
+       | (b & 3 ? 23 : 0)
+       | (b & 4 ? 24 : 0)
+       | (b & 5 ? 25 : 0)
+       | (b & 6 ? 26 : 0)
+       | (b & 7 ? 27 : 0)
+       | (b & 8 ? 28 : 0)
+       | (b & 9 ? 29 : 0)
+       | (b & 10 ? 30 : 0)
+       | (b & 11 ? 31 : 0)
+       | (b & 12 ? 32 : 0)
+       | (b & 13 ? 1 : 0)
+       | (b & 14 ? 2 : 0)
+       | (b & 15 ? 3 : 0)
+       | (b & 16 ? 4 : 0)
+       | (b & 17 ? 5 : 0)
+       | (b & 18 ? 6 : 0)
+       | (b & 19 ? 7 : 0)
+       | (b & 20 ? 8 : 0)
+       | (b & 21 ? 9 : 0));
+}
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 138700)
+++ gcc/cp/semantics.c	(working copy)
@@ -658,10 +658,13 @@ begin_if_stmt (void)
    IF_STMT.  */
 
 void
 finish_if_stmt_cond (tree cond, tree if_stmt)
 {
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
   add_stmt (if_stmt);
   THEN_CLAUSE (if_stmt) = push_stmt_list ();
 }
 
@@ -722,10 +725,12 @@ begin_while_stmt (void)
    WHILE_STMT.  */
 
 void
 finish_while_stmt_cond (tree cond, tree while_stmt)
 {
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
   finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond));
   simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
 }
 
 /* Finish a while-statement, which may be given by WHILE_STMT.  */
@@ -769,10 +774,12 @@ finish_do_body (tree do_stmt)
 
 void
 finish_do_stmt (tree cond, tree do_stmt)
 {
   cond = maybe_convert_cond (cond);
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
   DO_COND (do_stmt) = cond;
   finish_stmt ();
 }
 
 /* Finish a return-statement.  The EXPRESSION returned, if any, is as
@@ -788,10 +795,13 @@ finish_return_stmt (tree expr)
 
   if (flag_openmp && !check_omp_return ())
     return error_mark_node;
   if (!processing_template_decl)
     {
+      if (warn_sequence_point)
+	verify_sequence_points (expr);
+      
       if (DECL_DESTRUCTOR_P (current_function_decl)
 	  || (DECL_CONSTRUCTOR_P (current_function_decl)
 	      && targetm.cxx.cdtor_returns_this ()))
 	{
 	  /* Similarly, all destructors must run destructors for
@@ -847,10 +857,13 @@ finish_for_init_stmt (tree for_stmt)
    FOR_STMT.  */
 
 void
 finish_for_cond (tree cond, tree for_stmt)
 {
+  if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond));
   simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
 }
 
 /* Finish the increment-EXPRESSION in a for-statement, which may be
@@ -976,10 +989,13 @@ finish_switch_cond (tree cond, tree swit
 	    cond = index;
 	}
     }
   if (check_for_bare_parameter_packs (cond))
     cond = error_mark_node;
+  else if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
   add_stmt (switch_stmt);
   push_switch (switch_stmt);
   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while,  do conditions, for beg/cond/end expressions etc.
  2008-08-25  8:00 ` Manuel López-Ibáñez
@ 2008-08-25 17:29   ` Mark Mitchell
  2008-08-25 17:45     ` Manuel López-Ibáñez
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Mitchell @ 2008-08-25 17:29 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Gcc Patch List

Manuel López-Ibáñez wrote:

>> 2008-08-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
>>
>>        PR c++/17880
>> cp/
>>        * semantics.c (begin_if_stmt): Call verify_sequence_points.
>>        (begin_while_stmt): Likewise.
>>        (finish_do_body): Likewise.
>>        (finish_return_stmt): Likewise.
>>        (finish_for_init_stmt): Likewise.
>>        (finish_switch_condition): Likewise.
>> testsuite/
>>        * g++.dg/warn/sequence-pt-1.C: New.
>>        * g++.dg/warn/sequence-pt-pr17880.C: New.

Does it work to add the verify_sequence_points call inside
maybe_convert_cond instead?  Then, I think you will need it in fewer places.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.
  2008-08-25 17:29   ` Mark Mitchell
@ 2008-08-25 17:45     ` Manuel López-Ibáñez
  2008-08-25 17:56       ` Mark Mitchell
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel López-Ibáñez @ 2008-08-25 17:45 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Gcc Patch List

2008/8/25 Mark Mitchell <mark@codesourcery.com>:
> Manuel López-Ibáñez wrote:
>
>>> 2008-08-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
>>>
>>>        PR c++/17880
>>> cp/
>>>        * semantics.c (begin_if_stmt): Call verify_sequence_points.
>>>        (begin_while_stmt): Likewise.
>>>        (finish_do_body): Likewise.
>>>        (finish_return_stmt): Likewise.
>>>        (finish_for_init_stmt): Likewise.
>>>        (finish_switch_condition): Likewise.
>>> testsuite/
>>>        * g++.dg/warn/sequence-pt-1.C: New.
>>>        * g++.dg/warn/sequence-pt-pr17880.C: New.
>
> Does it work to add the verify_sequence_points call inside
> maybe_convert_cond instead?  Then, I think you will need it in fewer places.

I am not sure whether it works but maybe_convert_cond is called in
more places than those and verify_sequence_points looks quite
expensive. So I prefer to explicitly add it wherever is surely needed.
If you insist, I would prefer to call it
verify_sequence_points_and_maybe_convert_cond to avoid giving a false
impression of what it actually does.

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while,  do conditions, for beg/cond/end expressions etc.
  2008-08-25 17:45     ` Manuel López-Ibáñez
@ 2008-08-25 17:56       ` Mark Mitchell
  2008-08-25 18:11         ` Manuel López-Ibáñez
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Mitchell @ 2008-08-25 17:56 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Gcc Patch List

Manuel López-Ibáñez wrote:

> I am not sure whether it works but maybe_convert_cond is called in
> more places than those and verify_sequence_points looks quite
> expensive. So I prefer to explicitly add it wherever is surely needed.
> If you insist, I would prefer to call it
> verify_sequence_points_and_maybe_convert_cond to avoid giving a false
> impression of what it actually does.

It looks to me that it is called in *exactly* the places you changed:

semantics.c:578:maybe_convert_cond (tree cond)
semantics.c:663:  finish_cond (&IF_COND (if_stmt), maybe_convert_cond
(cond));
semantics.c:727:  finish_cond (&WHILE_COND (while_stmt),
maybe_convert_cond (cond));
semantics.c:773:  cond = maybe_convert_cond (cond);
semantics.c:852:  finish_cond (&FOR_COND (for_stmt), maybe_convert_cond
(cond));
semantics.c:3582:         t = maybe_convert_cond (t);

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.
  2008-08-25 17:56       ` Mark Mitchell
@ 2008-08-25 18:11         ` Manuel López-Ibáñez
  2008-08-25 18:44           ` Mark Mitchell
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel López-Ibáñez @ 2008-08-25 18:11 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Gcc Patch List

2008/8/25 Mark Mitchell <mark@codesourcery.com>:

> semantics.c:3582:         t = maybe_convert_cond (t);

This is called by finish_omp_clauses. I did not add it there. Should I?

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while,  do conditions, for beg/cond/end expressions etc.
  2008-08-25 18:11         ` Manuel López-Ibáñez
@ 2008-08-25 18:44           ` Mark Mitchell
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Mitchell @ 2008-08-25 18:44 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Gcc Patch List

Manuel López-Ibáñez wrote:
> 2008/8/25 Mark Mitchell <mark@codesourcery.com>:
> 
>> semantics.c:3582:         t = maybe_convert_cond (t);
> 
> This is called by finish_omp_clauses. I did not add it there. Should I?

You might want to ask Jakub about that; I'm not sure if OpenMP has
different sequence-point rules.  But, I would assume it does make sense
there.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PR c++/17880 -Wsequence-point doesn't warn inside if, while,  do conditions, for beg/cond/end expressions etc.
  2008-08-28  9:20 Manuel López-Ibáñez
@ 2008-08-28 14:48 ` Mark Mitchell
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Mitchell @ 2008-08-28 14:48 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Gcc Patch List

Manuel López-Ibáñez wrote:

> 2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
> 
> 	PR c++/17880
> cp/
> 	* semantics.c (maybe_convert_cond): Call verify_sequence_points.
> 	(finish_return_stmt): Likewise.
> 	(finish_switch_condition): Likewise.
> testsuite/
> 	* g++.dg/warn/sequence-pt-1.C: New.
> 	* g++.dg/warn/sequence-pt-pr17880.C: New.

OK.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 9+ messages in thread

* PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.
@ 2008-08-28  9:20 Manuel López-Ibáñez
  2008-08-28 14:48 ` Mark Mitchell
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel López-Ibáñez @ 2008-08-28  9:20 UTC (permalink / raw)
  To: Gcc Patch List; +Cc: Mark Mitchell

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

Updated patch addressing Mark's comments.

http://gcc.gnu.org/ml/gcc-patches/2008-08/msg00790.html

Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,ada

OK for trunk?

2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/17880
cp/
	* semantics.c (maybe_convert_cond): Call verify_sequence_points.
	(finish_return_stmt): Likewise.
	(finish_switch_condition): Likewise.
testsuite/
	* g++.dg/warn/sequence-pt-1.C: New.
	* g++.dg/warn/sequence-pt-pr17880.C: New.

[-- Attachment #2: fix-pr17880-try2.diff --]
[-- Type: text/plain, Size: 11156 bytes --]

Index: gcc/testsuite/g++.dg/warn/sequence-pt-1.C
===================================================================
--- gcc/testsuite/g++.dg/warn/sequence-pt-1.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/sequence-pt-1.C	(revision 0)
@@ -0,0 +1,109 @@
+/* Test for sequence point warnings.  */
+/* Origin: Michael Meeks in
+   <URL:http://gcc.gnu.org/ml/gcc-patches/1998-06/msg00316.html>,
+   adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>.  */
+/* { dg-do compile } */
+/* { dg-options "-Wsequence-point" } */
+
+struct s
+{
+  int a;
+};
+
+extern int fn (int);
+extern int fnb (int, int);
+extern int fnc (int *);
+extern int sprintf (char *, const char *, ...);
+
+typedef __SIZE_TYPE__ size_t;
+
+void
+foo (int a, int b, int n, int p, int *ptr, struct s *sptr,
+     int *ap, int *bp, int **cp, char *ans, int (*fnp[8])(int))
+{
+  int len;
+    
+  a = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = --a; /* { dg-warning "undefined" "sequence point warning" } */
+  a = ++a + b; /* { dg-warning "undefined" "sequence point warning" } */
+  a = a-- + b; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[n] = bp[n++]; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[--n] = bp[n]; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[++n] = bp[--n]; /* { dg-warning "undefined" "sequence point warning" } */
+  cp[n][n] = cp[n][n]++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
+  cp[n][p] = cp[n][n++]; /* { dg-warning "undefined" "sequence point warning" } */
+  *ptr++ = (size_t)ptr++; /* { dg-warning "undefined" "sequence point warning" } */
+  sptr->a = sptr->a++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
+  sptr->a = (size_t)(sptr++); /* { dg-warning "undefined" "sequence point warning" } */
+  *ptr++ = fn (*ptr); /* { dg-warning "undefined" "sequence point warning" } */
+  a = b = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  b = a = --b; /* { dg-warning "undefined" "sequence point warning" } */
+  a = 1 + (a = 1); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (a = b); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (a = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
+  a = (bp[a++] = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
+  a = b++ * b++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = fnb (b++, b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b++]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
+  a = (*fnp[b++]) (b); /* { dg-warning "undefined" "sequence point warning" } */
+  *ap = fnc (ap++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a += b) + (a += n); /* { dg-warning "undefined" "sequence point warning" } */
+  a =  (b, b++) + (b++, b); /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a++] += a; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a+=1] += a; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a++] += a++; /* { dg-warning "undefined" "sequence point warning" } */
+  ap[a+=1] += a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = a++, b = a; /* { dg-warning "undefined" "sequence point warning" } */
+  b = a, a = a++; /* { dg-warning "undefined" "sequence point warning" } */
+  a = (b++ ? n : a) + b; /* { dg-warning "undefined" "sequence point warning" } */
+  b ? a = a++ : a; /* { dg-warning "undefined" "sequence point warning" } */
+  b && (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a = a++) && b; /* { dg-warning "undefined" "sequence point warning" } */
+  b, (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
+  (a = a++), b; /* { dg-warning "undefined" "sequence point warning" } */
+  a ^= b ^= a ^= b; /* { dg-warning "undefined" "sequence point warning" } */
+
+  a = a; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = ! (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = - (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (double) (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  len = sprintf (ans, "%d", len++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = fn (a++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  b++, (b + b); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  (a = b++), (a = b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++, b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = b++ && b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = b++ || b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++ ? b++ : a); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  a = (b++ ? a : b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  ap[a++] += bp[b]; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  ap[a += 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */
+  *ptr < 128 ? *ptr++ : *(ptr += 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */
+
+  /* The following will be represented internally with a tree consisting of
+     many duplicated SAVE_EXPRs.  This caused the previous version of the
+     sequence point warning code to fail by running out of virtual memory.  */
+  a = ((b & 1 ? 21 : 0)
+       | (b & 2 ? 22 : 0)
+       | (b & 3 ? 23 : 0)
+       | (b & 4 ? 24 : 0)
+       | (b & 5 ? 25 : 0)
+       | (b & 6 ? 26 : 0)
+       | (b & 7 ? 27 : 0)
+       | (b & 8 ? 28 : 0)
+       | (b & 9 ? 29 : 0)
+       | (b & 10 ? 30 : 0)
+       | (b & 11 ? 31 : 0)
+       | (b & 12 ? 32 : 0)
+       | (b & 13 ? 1 : 0)
+       | (b & 14 ? 2 : 0)
+       | (b & 15 ? 3 : 0)
+       | (b & 16 ? 4 : 0)
+       | (b & 17 ? 5 : 0)
+       | (b & 18 ? 6 : 0)
+       | (b & 19 ? 7 : 0)
+       | (b & 20 ? 8 : 0)
+       | (b & 21 ? 9 : 0));
+}
Index: gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C
===================================================================
--- gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C	(revision 0)
@@ -0,0 +1,54 @@
+// PR 17880
+// { dg-do compile }
+// { dg-options "-Wsequence-point" }
+
+int
+foo (int x)
+{
+  unsigned int a;
+  int b;
+
+  b = (a += 5) > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a += 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a -= 5) > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = (a -= 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = a-- > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = a-- + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+  b = ++a > a;  // { dg-warning "undefined" "sequence point warning" }
+  b = ++a + a == 10;  // { dg-warning "undefined" "sequence point warning" }
+
+  if ((a += 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a += 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a -= 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if ((a -= 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (a-- > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (a-- + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (++a > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  if (++a + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
+  do {} while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  for ((a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
+  for (b = (a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
+  for (; (a += 5) > a;);  // { dg-warning "undefined" "sequence point warning" }
+  for (;; b = (a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
+  for (;; a++ + a++);  // { dg-warning "undefined" "sequence point warning" }
+  if (a) a++ - a--;    // { dg-warning "undefined" "sequence point warning" }
+  ((a +=5) > a) ? a : b; // { dg-warning "undefined" "sequence point warning" }
+  return (a++ - a--); // { dg-warning "undefined" "sequence point warning" }
+}
+
+void bar (int i)
+{
+  int a = i++ - i++; // { dg-warning "undefined" "sequence point warning" }
+} 
+
+void baz (int i)
+{
+  switch (i++ + i++)  // { dg-warning "undefined" "sequence point warning" }
+    {
+    case 1:
+      i++ - i++;  // { dg-warning "undefined" "sequence point warning" }
+    case 2:
+      break;
+    }
+}
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 139433)
+++ gcc/cp/semantics.c	(working copy)
@@ -570,11 +570,12 @@ finish_goto_stmt (tree destination)
 
   return add_stmt (build_stmt (GOTO_EXPR, destination));
 }
 
 /* COND is the condition-expression for an if, while, etc.,
-   statement.  Convert it to a boolean value, if appropriate.  */
+   statement.  Convert it to a boolean value, if appropriate.
+   In addition, verify sequence points if -Wsequence-point is enabled.  */
 
 static tree
 maybe_convert_cond (tree cond)
 {
   /* Empty conditions remain empty.  */
@@ -583,10 +584,13 @@ maybe_convert_cond (tree cond)
 
   /* Wait until we instantiate templates before doing conversion.  */
   if (processing_template_decl)
     return cond;
 
+  if (warn_sequence_point)
+    verify_sequence_points (cond);
+
   /* Do the conversion.  */
   cond = convert_from_reference (cond);
 
   if (TREE_CODE (cond) == MODIFY_EXPR
       && !TREE_NO_WARNING (cond)
@@ -788,10 +792,13 @@ finish_return_stmt (tree expr)
 
   if (flag_openmp && !check_omp_return ())
     return error_mark_node;
   if (!processing_template_decl)
     {
+      if (warn_sequence_point)
+	verify_sequence_points (expr);
+      
       if (DECL_DESTRUCTOR_P (current_function_decl)
 	  || (DECL_CONSTRUCTOR_P (current_function_decl)
 	      && targetm.cxx.cdtor_returns_this ()))
 	{
 	  /* Similarly, all destructors must run destructors for
@@ -976,10 +983,13 @@ finish_switch_cond (tree cond, tree swit
 	    cond = index;
 	}
     }
   if (check_for_bare_parameter_packs (cond))
     cond = error_mark_node;
+  else if (!processing_template_decl && warn_sequence_point)
+    verify_sequence_points (cond);
+
   finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
   SWITCH_STMT_TYPE (switch_stmt) = orig_type;
   add_stmt (switch_stmt);
   push_switch (switch_stmt);
   SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-08-27 15:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-12 15:18 PR c++/17880 -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc Manuel López-Ibáñez
2008-08-25  8:00 ` Manuel López-Ibáñez
2008-08-25 17:29   ` Mark Mitchell
2008-08-25 17:45     ` Manuel López-Ibáñez
2008-08-25 17:56       ` Mark Mitchell
2008-08-25 18:11         ` Manuel López-Ibáñez
2008-08-25 18:44           ` Mark Mitchell
2008-08-28  9:20 Manuel López-Ibáñez
2008-08-28 14:48 ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).