Bug 17880 - -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.
Summary: -Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/e...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: 4.4.0
Assignee: Manuel López-Ibáñez
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-10-07 09:52 UTC by Jakub Jelinek
Modified: 2008-08-27 16:25 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-08-09 13:09:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2004-10-07 09:52:54 UTC
/* { dg-do compile } */
/* { dg-options "-Wsequence-point" } */

int
foo (int x)
{
  unsigned int a = x;
  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 (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" } */
  return 0;
}

While it is certainly possible to call verify_sequence_points for each condition
etc. from c-parse.in and parse.y, I think much better would be to move this
warning to say c_genericize, walk over all statements and call
verify_sequence_points where needed.
Comment 1 Giovanni Bajo 2004-10-07 10:09:24 UTC
Notice, this is also related to PR 16202, which shows other cases where 
Wsequence-point is not working.
Comment 2 Andrew Pinski 2004-10-07 12:19:33 UTC
Cofirmed.
Comment 3 Andrew Pinski 2004-10-12 17:04:25 UTC
Note for the C++ front-end at this point we don't warn for the last for statement but we do for C, I 
have a fix for the problem (I fixed while fixing another problem).
Comment 4 Manuel López-Ibáñez 2008-08-09 12:38:55 UTC
Subject: Bug 17880

Author: manu
Date: Sat Aug  9 12:37:32 2008
New Revision: 138904

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138904
Log:
2008-08-09  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c/17880
	* c-typeck.c (digest_init): Call verify_sequence_points from here.
	(c_finish_return): Likewise.
	(c_start_case): Likewise.
	* c-common.c (warn_for_collisions_1): Use explicit location in
	warning.
	* c-parser.c (c_parser_condition): New. Call
	verify_sequence_points.
	(c_parser_paren_condition): Call c_parser_condition.
	(c_parser_for_statement): Call c_parser_condition.
testsuite/
	* gcc.dg/sequence-pt-pr17880.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/sequence-pt-pr17880.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-parser.c
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Manuel López-Ibáñez 2008-08-09 13:09:57 UTC
Fixed in the C front-end, broken in the C++ front-end. I also have a patch for this.
Comment 6 Manuel López-Ibáñez 2008-08-27 16:07:24 UTC
Subject: Bug 17880

Author: manu
Date: Wed Aug 27 16:06:00 2008
New Revision: 139625

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139625
Log:
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.

Added:
    trunk/gcc/testsuite/g++.dg/warn/sequence-pt-1.C
    trunk/gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Manuel López-Ibáñez 2008-08-27 16:25:20 UTC
Fixed in GCC 4.4. 

only 4631 bugs to go ;-)