c/10604: -Wall includes sign conversion warning [3.3 regression]

Zack Weinberg zack@codesourcery.com
Fri May 2 20:47:00 GMT 2003


It looks like this was experimentally changed as part of the C
option-parsing rewrite; since it clearly causes problems, it should be
put back the way it was.  I am testing the appended patch; Mark has
approved it for 3.3 if it works.  (The patch for 3.4 will be slightly
more invasive, because I'm going to get rid of a historical wart at
the same time; that will come later.)

zw

        PR c/10604
        * c-opts.c (c_common_decode_option <OPT_Wall>): Set
        warn_sign_compare for C++ only.
        * doc/invoke.texi: Clarify documentation of -Wsign-compare.
        * gcc.dg/compare7.c, g++.dg/warn/compare1.C: New testcases.

===================================================================
Index: c-opts.c
--- c-opts.c	21 Feb 2003 06:12:58 -0000	1.24.6.1
+++ c-opts.c	2 May 2003 20:38:22 -0000
@@ -699,7 +699,8 @@ c_common_decode_option (argc, argv)
       warn_parentheses = on;
       warn_return_type = on;
       warn_sequence_point = on;	/* Was C only.  */
-      warn_sign_compare = on;	/* Was C++ only.  */
+      if (c_language == clk_cplusplus)
+	warn_sign_compare = on;
       warn_switch = on;
       warn_strict_aliasing = on;
       
===================================================================
Index: doc/invoke.texi
--- doc/invoke.texi	23 Apr 2003 21:45:32 -0000	1.209.2.26
+++ doc/invoke.texi	2 May 2003 20:44:55 -0000
@@ -2634,8 +2634,8 @@ casts like @code{(unsigned) -1}.
 @cindex signed and unsigned values, comparison warning
 Warn when a comparison between signed and unsigned values could produce
 an incorrect result when the signed value is converted to unsigned.
-This warning is also enabled by @option{-W}; to get the other warnings
-of @option{-W} without this warning, use @samp{-W -Wno-sign-compare}.
+This warning is enabled by @option{-W}, and by @option{-Wall}
+in C++ only.
 
 @item -Waggregate-return
 @opindex Waggregate-return
===================================================================
Index: testsuite/g++.dg/warn/compare1.C
--- testsuite/g++.dg/warn/compare1.C	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/warn/compare1.C	2 May 2003 20:38:23 -0000
@@ -0,0 +1,10 @@
+/* -Wall is supposed to trigger -Wsign-compare for C++.  PR 10604.
+   See also gcc.dg/compare7.c.  */
+
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int f(unsigned a, int b)
+{
+  return a < b;  /* { dg-warning "signed and unsigned" } */
+}
===================================================================
Index: testsuite/gcc.dg/compare7.c
--- testsuite/gcc.dg/compare7.c	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/compare7.c	2 May 2003 20:38:24 -0000
@@ -0,0 +1,10 @@
+/* -Wall is not supposed to trigger -Wsign-compare for C.  PR 10604.
+   See also g++.dg/warn/compare1.C.  */
+
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int f(unsigned a, int b)
+{
+  return a < b;  /* { dg-bogus "signed and unsigned" } */
+}



More information about the Gcc-patches mailing list