[Bug c/48956] -Wconversion should warn when a complex value is assigned to a real result

manu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 11 22:39:00 GMT 2011


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/



More information about the Gcc-bugs mailing list