public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
Date: Sun, 12 Aug 2012 19:22:00 -0000	[thread overview]
Message-ID: <bug-54234-4-MWA9FFPWKM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-54234-4@http.gcc.gnu.org/bugzilla/>

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-12 19:21:41 UTC ---
(In reply to comment #1)
> The Fortran standard explicitly states that CMPLX returns
> a complex number with default real kind if the KIND= optional
> argument is not used.

Well, if it weren't valid, gfortran shouldn't warn but print an error. I
recently only found a bug in our program because of a warning about assigning
an REAL to an INTEGER, which should have been a REAL – thus, such warnings can
be helpful.


(In reply to comment #2)
> This is certainly a mistake made by lots of people,
> so I think a warning would be appropriate.

That's also the reason for suggesting this. The question is whether
-Wconversion (which is enabled by -Wall) or -Wconversion-extra (which is hidden
in the manual) is the better choice. It seems to be a somewhat common problem.
The case that one wants to have the default kind but uses a higher-precision
argument, seems to be rather rare; hence, I am inclined to warn already with
-Wconversion/-Wall.

(Side note: REAL always confuses me – for a complex number it returns the kind
of the argument - but for integer/real the default-kind.)


Untested patch – for -Wconversion-extra
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -1278,6 +1278,17 @@ gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr
*kind)
   if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
     return FAILURE;

+  if (y && !kind && gfc_option.warn_conversion_extra
+      && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
+    gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
+                    "might loose precision, consider using the KIND argument",
+                    gfc_typename (&x->ts), gfc_default_real_kind, &x->where);
+  else if (y && !kind && gfc_option.warn_conversion_extra
+          && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
+    gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
+                    "might loose precision, consider using the KIND argument",
+                    gfc_typename (&y->ts), gfc_default_real_kind, &y->where);
+
   return SUCCESS;
 }


  parent reply	other threads:[~2012-08-12 19:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-12 14:26 [Bug fortran/54234] New: " burnus at gcc dot gnu.org
2012-08-12 16:12 ` [Bug fortran/54234] " kargl at gcc dot gnu.org
2012-08-12 16:23 ` tkoenig at gcc dot gnu.org
2012-08-12 19:22 ` burnus at gcc dot gnu.org [this message]
2012-08-14  9:35 ` burnus at gcc dot gnu.org
2012-08-14 10:22 ` burnus at gcc dot gnu.org
2012-08-14 10:30 ` burnus at gcc dot gnu.org

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-54234-4-MWA9FFPWKM@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).