public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/48956] -Wconversion should warn when a complex value is assigned to a real result
Date: Wed, 11 May 2011 22:39:00 -0000	[thread overview]
Message-ID: <bug-48956-4-ynMWue2Y5J@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-48956-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48956

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-05-11 21:57:54 UTC ---
(In reply to comment #4)
> Created attachment 24230 [details]
> patch to add a -Wconversion warning for complex -> real conversions
> 
> I believe the attached patch (against gcc 4.6.0) implements the feature I
> requested.  It emits a warning for implicit conversions of complex types to
> real (or integer) types.  It also emits a warning for similarly converting
> complex constants, unless the imaginary part of the constant is zero in which
> case it is treated as a real (or integer) constant given by the real part.

Nice! The patch looks almost ok but I cannot approve it. 

Some small issues:

* The code must follow GCC style, which is described in detail here
http://gcc.gnu.org/contribute.html#standards, but it is just easier too look
code around and follow the same style for braces, comments (they have to start
uppercase and end with a period), you have to add /* Fall through. */ to mark
deliberate fall-through in switches, etc.

* I would say (TREE_CODE (type) != COMPLEX_TYPE) rather than (!(TREE_CODE
(type) == COMPLEX_TYPE)). Even better, test first that == COMPLEX_TYPE, if so
you can return, otherwise, the zero imaginary part, else warning. Does that
sound right?

* You need to add the testcase to the testsuite. Look in
testsuite/gcc.dg/c-c++-common/Wconversion-real.c for an example. More info:
http://gcc.gnu.org/wiki/HowToPrepareATestcase

* Patches should be always be done against a recent SVN revision. I think this
patch should be safe to backport to GCC 4.6, but perhaps the release managers
may disagree (it does generate new warnings, which some people may find
bothersome if they use -Werror).

* Patches need to be bootstrapped and regression tested:
http://gcc.gnu.org/contribute.html#testing . There are scripts that mostly
automate this process. Take a look at contrib/ or this script of mine:
http://gcc.gnu.org/wiki/ManuelL%C3%B3pezIb%C3%A1%C3%B1ez?action=AttachFile&do=view&target=gccfarming

* Finally, patches should be sent to gcc-patches@gcc.gnu.org with a Changelog.
Take a look at the archives to have an idea of the proper way:
http://gcc.gnu.org/ml/gcc-patches/2011-05/


  parent reply	other threads:[~2011-05-11 22:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-11  3:26 [Bug c/48956] New: " stevenj at alum dot mit.edu
2011-05-11  0:11 ` [Bug c/48956] " stevenj at alum dot mit.edu
2011-05-11  8:27 ` manu at gcc dot gnu.org
2011-05-11  8:50 ` manu at gcc dot gnu.org
2011-05-11 20:34 ` stevenj at alum dot mit.edu
2011-05-11 22:08 ` manu at gcc dot gnu.org
2011-05-11 22:39 ` manu at gcc dot gnu.org [this message]
2011-05-12 23:11 ` stevenj at alum dot mit.edu
2011-05-12 23:18 ` manu at gcc dot gnu.org
2012-03-24 19:15 ` manu at gcc dot gnu.org
2014-11-07 10:14 ` paolo.carlini at oracle dot com
2015-01-01 18:15 ` maltsevm at gmail dot com
2015-05-15 18:03 ` miyuki at gcc dot gnu.org
2015-05-15 18:47 ` manu at gcc dot gnu.org
2015-06-24 21:53 ` matt at bitbashing dot io
2015-06-24 22:08 ` manu at gcc dot gnu.org
2015-06-24 22:13 ` matt at bitbashing dot io

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=bug-48956-4-ynMWue2Y5J@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).