From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2842 invoked by alias); 12 Aug 2012 19:22:02 -0000 Received: (qmail 2829 invoked by uid 22791); 12 Aug 2012 19:22:01 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 12 Aug 2012 19:21:42 +0000 From: "burnus at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg00695.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D54234 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #3 from Tobias Burnus 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=3D 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 assigni= ng an REAL to an INTEGER, which should have been a REAL =E2=80=93 thus, such w= arnings 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 hi= dden in the manual) is the better choice. It seems to be a somewhat common probl= em. 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 =E2=80=93 for a complex number it retur= ns the kind of the argument - but for integer/real the default-kind.) Untested patch =E2=80=93 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) =3D=3D FAILURE) return FAILURE; + if (y && !kind && gfc_option.warn_conversion_extra + && x->ts.type =3D=3D 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 argume= nt", + gfc_typename (&x->ts), gfc_default_real_kind, &x->wher= e); + else if (y && !kind && gfc_option.warn_conversion_extra + && y->ts.type =3D=3D BT_REAL && y->ts.kind > gfc_default_real_ki= nd) + gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L= " + "might loose precision, consider using the KIND argume= nt", + gfc_typename (&y->ts), gfc_default_real_kind, &y->wher= e); + return SUCCESS; }