public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Segher Boessenkool <segher@koffie.nl>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c/9072: -Wconversion should be split into two distinct flags
Date: Sat, 28 Dec 2002 22:16:00 -0000	[thread overview]
Message-ID: <20021229061601.21440.qmail@sources.redhat.com> (raw)

The following reply was made to PR c/9072; it has been noted by GNATS.

From: Segher Boessenkool <segher@koffie.nl>
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  <segher@koffie.nl>
 
 	* 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	other threads:[~2002-12-29  6:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-28 22:16 Segher Boessenkool [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-02-03 16:36 Wolfgang Bangerth
2003-02-03  2:36 Agthorr
2003-02-03  2:06 Segher Boessenkool
2003-02-03  0:16 Joseph S. Myers
2003-02-02 22:54 bangerth
2002-12-29  4:06 Joseph S. Myers
2002-12-29  1:06 Zack Weinberg
2002-12-29  0:56 Segher Boessenkool
2002-12-29  0:46 Zack Weinberg
2002-12-27 15:36 Matthias Klose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021229061601.21440.qmail@sources.redhat.com \
    --to=segher@koffie.nl \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).