From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21455 invoked by alias); 29 Dec 2002 06:16:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 21441 invoked by uid 71); 29 Dec 2002 06:16:01 -0000 Date: Sat, 28 Dec 2002 22:16:00 -0000 Message-ID: <20021229061601.21440.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Segher Boessenkool Subject: Re: c/9072: -Wconversion should be split into two distinct flags Reply-To: Segher Boessenkool X-SW-Source: 2002-12/txt/msg01359.txt.bz2 List-Id: The following reply was made to PR c/9072; it has been noted by GNATS. From: Segher Boessenkool To: 128950@bugs.debian.org, gcc-patches@gcc.gnu.org Cc: gcc-gnats@gcc.gnu.org, debian-gcc@lists.debian.org Subject: Re: c/9072: -Wconversion should be split into two distinct flags Date: Sat, 28 Dec 2002 17:56:27 +0100 Matthias Klose wrote: > > The -Wconversion option to gcc is documented as doing two things: > > ------------------------------------------------------------------------ > `-Wconversion' > Warn if a prototype causes a type conversion that is different > from what would happen to the same argument in the absence of a > prototype. This includes conversions of fixed point to floating > and vice versa, and conversions changing the width or signedness > of a fixed point argument except when the same as the default > promotion. > > Also, warn if a negative integer constant expression is implicitly > converted to an unsigned type. For example, warn about the > assignment `x = -1' if `x' is unsigned. But do not warn about > explicit casts like `(unsigned) -1'. > ------------------------------------------------------------------------ > > It'd be nice if these two behaviors were two controlled via two > separate flags. The second behavior would have caught a bug I've been > hunting for hours, while the first behavior is very undesirable to me > (and useless since I also compile with -Wstrict-prototypes). I remember having been annoyed by -Wconversion its behaviour, too. Maybe this patch will do what you want? Segher 2002-12-28 Segher Boessenkool * c-typeck.c (convert_arguments): Don't warn about arguments passed as `float' unless -Wtraditional given. Add warning to -Wconversion for passing floating point arguments in smaller precision. Add warning to -Wtraditional for passing integers with different width due to prototype. * doc/invoke.texi (Warning Options): Document this. Clarify. * doc/trouble.texi (Protoize Caveats): Ditto. *** ../../gcc-clean/gcc/c-typeck.c Fri Dec 27 03:21:39 2002 --- ./c-typeck.c Sat Dec 28 16:44:19 2002 *************** convert_arguments (typelist, values, nam *** 1645,1657 **** { /* Warn if any argument is passed as `float', since without a prototype it would be `double'. */ ! if (formal_prec == TYPE_PRECISION (float_type_node)) warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1); } /* Detect integer changing in width or signedness. ! These warnings are only activated with -Wconversion, not with -Wtraditional. */ ! else if (warn_conversion && INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (val))) { tree would_have_been = default_conversion (val); --- 1645,1659 ---- { /* Warn if any argument is passed as `float', since without a prototype it would be `double'. */ ! if (warn_traditional && formal_prec == TYPE_PRECISION (float_type_node)) warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1); + else if (warn_conversion && TYPE_PRECISION (TREE_TYPE (val)) < formal_prec) + warn_for_assignment ("%s with smaller precision due to prototype", (char *) 0, name, parmnum + 1); } /* Detect integer changing in width or signedness. ! The warning for signedness is only activated with -Wconversion, not with -Wtraditional. */ ! else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (val))) { tree would_have_been = default_conversion (val); *************** convert_arguments (typelist, values, nam *** 1666,1671 **** --- 1668,1675 ---- else if (formal_prec != TYPE_PRECISION (type1)) warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1); else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1)) + ; + else if (!warn_conversion) ; /* Don't complain if the formal parameter type is an enum, because we can't tell now whether *** ../../gcc-clean/gcc/doc/invoke.texi Fri Dec 27 03:21:40 2002 --- ./doc/invoke.texi Sat Dec 28 16:27:54 2002 *************** traditional C case. *** 2600,2610 **** @item Conversions by prototypes between fixed/floating point values and vice ! versa. The absence of these prototypes when compiling with traditional C would cause serious problems. This is a subset of the possible conversion warnings, for the full set use @option{-Wconversion}. @item Use of ISO C style function definitions. This warning intentionally is @emph{not} issued for prototype declarations or variadic functions because these ISO C features will appear in your code when using --- 2600,2616 ---- @item Conversions by prototypes between fixed/floating point values and vice ! versa, and conversion by prototypes between different width types when ! not equal to the default promotions. ! The absence of these prototypes when compiling with traditional C would cause serious problems. This is a subset of the possible conversion warnings, for the full set use @option{-Wconversion}. @item + Use of @code{float} in prototypes. Traditional C would pass such + parameters as @code{double}, while ISO C does not. + + @item Use of ISO C style function definitions. This warning intentionally is @emph{not} issued for prototype declarations or variadic functions because these ISO C features will appear in your code when using *************** this is why we did not make @option{-Wal *** 2671,2681 **** @item -Wconversion @opindex Wconversion ! Warn if a prototype causes a type conversion that is different from what ! would happen to the same argument in the absence of a prototype. This ! includes conversions of fixed point to floating and vice versa, and ! conversions changing the width or signedness of a fixed point argument ! except when the same as the default promotion. Also, warn if a negative integer constant expression is implicitly converted to an unsigned type. For example, warn about the assignment --- 2677,2687 ---- @item -Wconversion @opindex Wconversion ! Warn if a prototype causes an implicit type conversion that is different ! from the default promotion. This includes conversions of fixed point to ! floating and vice versa, and conversions changing the width or ! signedness of a fixed point argument (except when the same as the default ! promotion). Also, warn if a negative integer constant expression is implicitly converted to an unsigned type. For example, warn about the assignment *** ../../gcc-clean/gcc/doc/trouble.texi Mon Sep 16 00:48:05 2002 --- ./doc/trouble.texi Sat Dec 28 16:29:53 2002 *************** without them. *** 1110,1117 **** @opindex Wconversion You can find all the places where this problem might occur by compiling ! the program with the @option{-Wconversion} option. It prints a warning ! whenever an argument is converted. @item Both conversion programs can be confused if there are macro calls in and --- 1110,1117 ---- @opindex Wconversion You can find all the places where this problem might occur by compiling ! the program with the @option{-Wtraditional -Wconversion} options. It ! prints a warning whenever an argument is converted. @item Both conversion programs can be confused if there are macro calls in and