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  <[EMAIL PROTECTED]>

        * 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



Reply via email to