re PR c/10604 (-Wall includes sign conversion warning [3.3 regression])

PR c/10604

	* c-common.c (warn_sign_compare): Initialize to -1.
	* c-opts.c (c_common_init_options): Don't set warn_sign_compare here.
	(c_common_decode_option <OPT_Wall>): Set warn_sign_compare
	for C++ only.
	(c_common_post_options): Set warn_sign_compare from extra_warnings
	if it's still -1 at this point.

	* toplev.c (maybe_warn_unused_parameter): New static variable.
	(set_Wextra): New static function.
	(W_options): Remove "extra".
	(decode_W_option): Call set_Wextra.
	(independent_decode_option): Likewise.
	(set_Wunused): Cooperate with set_Wextra in setting
	warn_unused_parameter.
	(rest_of_compilation): No need to check extra_warnings as
	well as warn_uninitialized.

	* c-typeck.c (build_binary_op, build_conditional_expr):
	No need to check extra_warnings as well as warn_sign_compare.
	(internal_build_compound_expr): No need to check extra_warnings
	as well as warn_unused_value.
	* function.c (expand_function_end): No need to check extra_warnings
	as well as warn_unused_parameter.
	* stmt.c (expand_expr_stmt_value): No need to check extra_warnings
	as well as warn_unused_value.
	* cp/typeck.c (build_x_compound_expr): No need to check
	extra_warnings as well as warn_unused_value.

	* doc/invoke.texi: Clarify documentation of -Wsign-compare.
	* gcc.dg/compare7.c, g++.dg/warn/compare1.C: New testcases.

	* Makefile.in: Disable -Werror for gengtype-lex.o.

From-SVN: r66436
This commit is contained in:
Zack Weinberg 2003-05-03 21:44:31 +00:00
parent e7b5f0c9b4
commit 87f85ea066
13 changed files with 573 additions and 495 deletions

File diff suppressed because it is too large Load Diff

View File

@ -165,6 +165,8 @@ insn-conditions.o-warn = -Wno-error
# Bison-1.75 output often yields (harmless) -Wtraditional warnings
gengtype-yacc.o-warn = -Wno-error
c-parse.o-warn = -Wno-error
# flex output may yield harmless "no previous prototype" warnings
gengtype-lex.o-warn = -Wno-error
# All warnings have to be shut off in stage1 if the compiler used then
# isn't gcc; configure determines that. WARN_CFLAGS will be either

View File

@ -304,9 +304,10 @@ int warn_parentheses;
int warn_missing_braces;
/* Warn about comparison of signed and unsigned values.
If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */
If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified
(in which case -Wextra gets to decide). */
int warn_sign_compare;
int warn_sign_compare = -1;
/* Nonzero means warn about usage of long long when `-pedantic'. */

View File

@ -595,8 +595,6 @@ c_common_init_options (lang)
flag_const_strings = (lang == clk_cplusplus);
warn_pointer_arith = (lang == clk_cplusplus);
if (lang == clk_c)
warn_sign_compare = -1;
}
/* Handle one command-line option in (argc, argv).
@ -805,7 +803,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;
@ -1526,6 +1525,11 @@ c_common_post_options (pfilename)
}
}
/* -Wextra implies -Wsign-compare, but not if explicitly
overridden. */
if (warn_sign_compare == -1)
warn_sign_compare = extra_warnings;
/* Special format checking options don't work without -Wformat; warn if
they are used. */
if (warn_format_y2k && !warn_format)

View File

@ -2458,8 +2458,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
converted = 1;
resultcode = xresultcode;
if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare != 0)
&& skip_evaluation == 0)
if (warn_sign_compare && skip_evaluation == 0)
{
int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
@ -3448,8 +3447,7 @@ build_conditional_expr (ifexp, op1, op2)
and later code won't know it used to be different.
Do this check on the original types, so that explicit casts
will be considered, but default promotions won't. */
if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare)
&& !skip_evaluation)
if (warn_sign_compare && !skip_evaluation)
{
int unsigned_op1 = TREE_UNSIGNED (TREE_TYPE (orig_op1));
int unsigned_op2 = TREE_UNSIGNED (TREE_TYPE (orig_op2));
@ -3603,7 +3601,7 @@ internal_build_compound_expr (list, first_p)
/* The left-hand operand of a comma expression is like an expression
statement: with -Wextra or -Wunused, we should warn if it doesn't have
any side-effects, unless it was explicitly cast to (void). */
if ((extra_warnings || warn_unused_value)
if (warn_unused_value
&& ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
&& VOID_TYPE_P (TREE_TYPE (TREE_VALUE (list)))))
warning ("left-hand operand of comma expression has no effect");

View File

@ -1,3 +1,9 @@
2003-05-03 Zack Weinberg <zack@codesourcery.com>
PR c/10604
* cp/typeck.c (build_x_compound_expr): No need to check
extra_warnings as well as warn_unused_value.
2003-05-03 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/9364, c++/10553, c++/10586
@ -49,7 +55,7 @@
tsubst, tsubst_expr, instantiate_decl): Likewise.
* semantics.c (genrtl_try_block, finish_label_stmt,
begin_class_definition, expand_body,
genrtl_finish_function): Likewise.
genrtl_finish_function): Likewise.
* tree.c (build_min_nt, build_min): Likewise.
2003-05-01 Mark Mitchell <mark@codesourcery.com>
@ -156,7 +162,7 @@
2003-04-24 Sylvain Pion <Sylvain.Pion@mpi-sb.mpg.de>
* call.c (print_z_candidates): Fix off by one error.
* call.c (print_z_candidates): Fix off by one error.
2003-04-24 Nathan Sidwell <nathan@codesourcery.com>
@ -192,7 +198,7 @@
PR c++/10446
* search.c (lookup_fnfields_1): Handle empty slots in the method
vector.
PR c++/10428
* decl.c (check_elaborated_type_specifier): New function, split
out from ...
@ -223,7 +229,7 @@
PR c++/9881
* typeck.c (build_unary_op): Fold all COMPONENT_REF addr
expressions. Reverts my 2002-08-08 patch.
* typeck.c (comp_ptr_ttypes_real): Swap final && operands for
cheaper early exit.

View File

@ -4793,7 +4793,7 @@ build_x_compound_expr (list)
/* the left-hand operand of a comma expression is like an expression
statement: we should warn if it doesn't have any side-effects,
unless it was explicitly cast to (void). */
if ((extra_warnings || warn_unused_value)
if (warn_unused_value
&& !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
&& VOID_TYPE_P (TREE_TYPE (TREE_VALUE(list)))))
warning("left-hand operand of comma expression has no effect");

View File

@ -6956,13 +6956,8 @@ expand_function_end (filename, line, end_bindings)
}
}
/* Warn about unused parms if extra warnings were specified. */
/* Either ``-Wextra -Wunused'' or ``-Wunused-parameter'' enables this
warning. WARN_UNUSED_PARAMETER is negative when set by
-Wunused. Note that -Wall implies -Wunused, so ``-Wall -Wextra'' will
also give these warnings. */
if (warn_unused_parameter > 0
|| (warn_unused_parameter < 0 && extra_warnings))
/* Possibly warn about unused parameters. */
if (warn_unused_parameter)
{
tree decl;

View File

@ -2174,7 +2174,7 @@ expand_expr_stmt_value (exp, want_value, maybe_last)
{
if (! TREE_SIDE_EFFECTS (exp))
{
if ((extra_warnings || warn_unused_value)
if (warn_unused_value
&& !(TREE_CODE (exp) == CONVERT_EXPR
&& VOID_TYPE_P (TREE_TYPE (exp))))
warning_with_file_and_line (emit_filename, emit_lineno,

View File

@ -1,3 +1,8 @@
2003-05-03 Zack Weinberg <zack@codesourcery.com>
PR c/10604
* gcc.dg/compare7.c, g++.dg/warn/compare1.C: New testcases.
2003-05-03 Kazu Hirata <kazu@cs.umass.edu>
* gcc.dg/m-un-2.c: Fix the typedef of size_t.
@ -43,7 +48,7 @@
* lib/old-dejagnu.exp: Remove.
* g++.old-deja/old-deja.exp: Use dg.exp, not old-dejagnu.exp.
* g++.old-deja: Revise all tests to use dg commands.
2003-04-30 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/9432, c++/9528
@ -151,7 +156,7 @@
PR c++/10451
* g++.dg/parse/crash4.C: New test.
PR c++/9847
* g++.dg/parse/crash5.C: New test.
@ -166,7 +171,7 @@
2003-04-22 Devang Patel <dpatel@apple.com>
* gcc.dg/cpp/trad/funlike-5.c: New test.
2003-04-21 Andreas Tobler <a.tobler@schweiz.ch>
* g++.dg/other/packed1.C: Fix dg options.

View File

@ -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" } */
}

View File

@ -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" } */
}

View File

@ -124,6 +124,7 @@ static int decode_f_option PARAMS ((const char *));
static int decode_W_option PARAMS ((const char *));
static int decode_g_option PARAMS ((const char *));
static unsigned int independent_decode_option PARAMS ((int, char **));
static void set_Wextra PARAMS ((int));
static void print_version PARAMS ((FILE *, const char *));
static int print_single_switch PARAMS ((FILE *, int, int, const char *,
@ -1463,6 +1464,9 @@ int warn_unused_parameter;
int warn_unused_variable;
int warn_unused_value;
/* Used for cooperation between set_Wunused and set_Wextra. */
static int maybe_warn_unused_parameter;
/* Nonzero to warn about code which is never reached. */
int warn_notreached;
@ -1586,8 +1590,6 @@ static const lang_independent_options W_options[] =
N_("Warn when an optimization pass is disabled") },
{"deprecated-declarations", &warn_deprecated_decl, 1,
N_("Warn about uses of __attribute__((deprecated)) declarations") },
{"extra", &extra_warnings, 1,
N_("Print extra (possibly unwanted) warnings") },
{"missing-noreturn", &warn_missing_noreturn, 1,
N_("Warn about functions which might be candidates for attribute noreturn") },
{"strict-aliasing", &warn_strict_aliasing, 1,
@ -1600,17 +1602,34 @@ set_Wunused (setting)
{
warn_unused_function = setting;
warn_unused_label = setting;
/* Unused function parameter warnings are reported when either ``-W
-Wunused'' or ``-Wunused-parameter'' is specified. Differentiate
-Wunused by setting WARN_UNUSED_PARAMETER to -1. */
if (!setting)
warn_unused_parameter = 0;
else if (!warn_unused_parameter)
warn_unused_parameter = -1;
/* Unused function parameter warnings are reported when either
``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
Thus, if -Wextra has already been seen, set warn_unused_parameter;
otherwise set maybe_warn_extra_parameter, which will be picked up
by set_Wextra. */
maybe_warn_unused_parameter = setting;
warn_unused_parameter = (setting && extra_warnings);
warn_unused_variable = setting;
warn_unused_value = setting;
}
static void
set_Wextra (setting)
int setting;
{
extra_warnings = setting;
warn_unused_value = setting;
warn_unused_parameter = (setting && maybe_warn_unused_parameter);
/* We save the value of warn_uninitialized, since if they put
-Wuninitialized on the command line, we need to generate a
warning about not using it without also specifying -O. */
if (setting == 0)
warn_uninitialized = 0;
else if (warn_uninitialized != 1)
warn_uninitialized = 2;
}
/* The following routines are useful in setting all the flags that
-ffast-math and -fno-fast-math imply. */
@ -3206,7 +3225,7 @@ rest_of_compilation (decl)
| (flag_thread_jumps ? CLEANUP_THREADING : 0));
timevar_pop (TV_FLOW);
if (warn_uninitialized || extra_warnings)
if (warn_uninitialized)
{
uninitialized_vars_warning (DECL_INITIAL (decl));
if (extra_warnings)
@ -3874,6 +3893,7 @@ display_help ()
W_options[i].string, _(description));
}
printf (_(" -Wextra Print extra (possibly unwanted) warnings\n"));
printf (_(" -Wunused Enable unused warnings\n"));
printf (_(" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n"));
printf (_(" -p Enable function profiling\n"));
@ -4256,11 +4276,11 @@ decode_W_option (arg)
}
else if (!strcmp (arg, "extra"))
{
/* We save the value of warn_uninitialized, since if they put
-Wuninitialized on the command line, we need to generate a
warning about not using it without also specifying -O. */
if (warn_uninitialized != 1)
warn_uninitialized = 2;
set_Wextra (1);
}
else if (!strcmp (arg, "no-extra"))
{
set_Wextra (0);
}
else
return 0;
@ -4539,15 +4559,9 @@ independent_decode_option (argc, argv)
break;
case 'W':
/* For backward compatibility, -W is the same as -Wextra. */
if (arg[1] == 0)
{
extra_warnings = 1;
/* We save the value of warn_uninitialized, since if they put
-Wuninitialized on the command line, we need to generate a
warning about not using it without also specifying -O. */
if (warn_uninitialized != 1)
warn_uninitialized = 2;
}
set_Wextra (1);
else
return decode_W_option (arg + 1);
break;